Jump to content

A small section of extremely simple code is causing error 500.


gergy008

Recommended Posts

Okay, I have no idea how this works out but this is really getting on my nerves.

 

Here is my logic for the following code. I manually register a user, It goes into the database and dispatches an email notification explaining that a user must activate their account and change their user name (OPTIONAL) and password. In the email, There is an automatically generated password with the username, And a link to activate the account. This leads to stage 1 of the activation process, In this stage the user is accepted, Registered as a verified user and then is sent to another page to change the details like login and password. As far as I know this page works except through trial and error I found that this little snippet of code is causing browsers to show an error 500 page, If I remove this the page works:

<?php
if($messages){
displayErrors($messages);
} else {
echo("<p align=\"center\" class=\"standard\">Your account has been activated.</p><p align=\"center\" class=\"standard\">You now need to change your password. If you like you can also change your username, Remember that you only have 3 days to do so and this change will be permanent.</p>");
}
?>

and this is the displayErrors function:

<?php
function displayErrors($messages) {
print("<p align=\"center\" class=\"standard\">"."<b>There were problems with the previous action:</b>\n<ul>\n");
foreach($messages as $msg){
	print("<li>$msg</li>\n");
}
print("</ul>\n"."</p>");
}
?>

 

The displayErrors function is in a file called functions.php, Which is included in config.php, Which is included in every page including this one.

 

The entire "Change password and login page thingie" is here:

 

<?php
include("config.php");
global $link, $messages;
require_once('recaptchalib.php');
if($_GET['error']){
$id=$_GET['id'];
$messages[]="There is more than one or no accounts with the verification code you are using. <a href=\"mailto:[email protected]?subject=Two or no accounts with activation ID of $id\">Click here to email us about this and have the problem sorted.</a>";
doIndex();
exit;
}
if(isset($_POST['submit'])){
if(!isset($_POST['activationid'])){
	die("Doesn't exist -.- might as well quit this is *STUFF* -.-");
}
$privatekey = "YOUR NOT HAVING THIS";
$resp = recaptcha_check_answer ($privatekey,
				$_SERVER["REMOTE_ADDR"],
				$_POST["recaptcha_challenge_field"],
				$_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
	$messages[]="The code you entered is incorrect. Please go back and try again!";
	doIndex();
	exit; // exit or the below lines will be processed.
} else {
	//This is where the fun starts!
	$login=$_POST['login'];
	$passw=$_POST['password'];
	$passc=$_POST['passwordc'];
	$id2=$_POST['activationid'];
	$changinglogin=false;
	$get1=excDB("SELECT * FROM `users` WHERE `activeID`='$id2'");
	if($get1[0]){ $get1=$get1[1]; } else { die($get1[2]); }
	$pro1=mysql_fetch_array($get1);
	if($pro1['login']!=$login){
		$changinglogin=true;
		field_validator("Login", $login, "alphanumeric", 4, 15);
	}
	field_validator("Password", $passw, "string", 6, 20);
	if($passw!=$passc){
		$messages[]="The passwords do not match, Please make sure that the passwords are the same!";
	}
	if($messages){
		doIndex();
		exit;
	}
	$passcl=mysql_escape_string($passw);
	$passen=md5($passcl);
	if($changinglogin){
		$wri1=excDB("UPDATE `users` SET `login`='$login', `password`='$passen', `passchange`='1', `loginchange`='1' WHERE `activeID`='$id2';");
		if($wri1[0]){ $wri1=$wri1[1]; } else { die($wri1[2]); }
		header("Location: login.php?created");
	} else {
		$wri1=excDB("UPDATE `users` SET `password`='$passen', `passchange`='1', `loginchange`='0' WHERE `activeID`='$id2';");
		if($wri1[0]){ $wri1=$wri1[1]; } else { die($wri1[2]); }
		header("Location: login.php?created2");
	}
}
} else { 
doIndex();
}
function doIndex(){
?>
<!DOCTYPE html>
<head>
<title>Family Rental System! - Rent your DVDs here - Design by Alex, Coding by Gergy008</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" href="css/main.css" rel="stylesheet">
<style type="text/css">
<!--
body {
background-color: #333333;
}
-->
</style></head>
<body style="text-align:center;">
<div class="first">
<div class="backgrounder1"></div>
<div class="headerbar1"></div>
<div class="headerbar2"></div>
</div>
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="900">
  <tr>
   <td><img src="images/spacer.gif" width="52" height="1" border="0" alt="" /></td>
   <td><img src="images/spacer.gif" width="123" height="1" border="0" alt="" /></td>
   <td><img src="images/spacer.gif" width="352" height="1" border="0" alt="" /></td>
   <td><img src="images/spacer.gif" width="33" height="1" border="0" alt="" /></td>
   <td><img src="images/spacer.gif" width="55" height="1" border="0" alt="" /></td>
   <td><img src="images/spacer.gif" width="110" height="1" border="0" alt="" /></td>
   <td><img src="images/spacer.gif" width="110" height="1" border="0" alt="" /></td>
   <td><img src="images/spacer.gif" width="50" height="1" border="0" alt="" /></td>
   <td><img src="images/spacer.gif" width="15" height="1" border="0" alt="" /></td>
   <td><img src="images/spacer.gif" width="1" height="1" border="0" alt="" /></td>
  </tr>

  <tr>
   <td colspan="9" background="images/template.slice.1.png"> </td>
   <td><img src="images/spacer.gif" width="1" height="20" border="0" alt="" /></td>
  </tr>
  <tr>
   <td colspan="5" background="images/template.slice.2.png"> </td>
   <td colspan="2" rowspan="2" background="images/template.slice.3.png"><span class="login"><?php echo(loginHandler()); ?></span></td>
   <td colspan="2" rowspan="3" background="images/template.slice.4.png"> </td>
   <td><img src="images/spacer.gif" width="1" height="30" border="0" alt="" /></td>
  </tr>
  <tr>
   <td rowspan="8" background="images/template.slice.5.png"> </td>
   <td colspan="2" background="images/template.slice.6.png"><form>
     <div align="center">
       <input name="textfield" type="text" id="textfield" size="40" style="height:16px;">
       <input type="submit" name="button" id="button" value="Search" style="height:20px;">
     </div>
   </form></td>
   <td colspan="2" rowspan="2" background="images/template.slice.7.png"> </td>
   <td><img src="images/spacer.gif" width="1" height="30" border="0" alt="" /></td>
  </tr>
  <tr>
   <td colspan="2" rowspan="3" background="images/template.slice.8.png"><p> </p>
    <p> </p></td>
   <td colspan="2" background="images/template.slice.9.png"> </td>
   <td><img src="images/spacer.gif" width="1" height="70" border="0" alt="" /></td>
  </tr>
  <tr>
   <td rowspan="2" background="images/template.slice.10.png"> </td>
   <td colspan="4" background="images/template.slice.11.png"> </td>
   <td rowspan="6" background="images/template.slice.12.png"> </td>
   <td><img src="images/spacer.gif" width="1" height="30" border="0" alt="" /></td>
  </tr>
  <tr>
   <td colspan="4" background="images/template.slice.13.png"></td>
   <td><img src="images/spacer.gif" width="1" height="8" border="0" alt="" /></td>
  </tr>
  <tr>
   <td rowspan="4" background="images/template.slice.14.png"> </td>
   <td colspan="4" background="images/template.slice.15.png"> </td>
   <td colspan="2" rowspan="4" background="images/template.slice.16.png"> </td>
   <td><img src="images/spacer.gif" width="1" height="35" border="0" alt="" /></td>
  </tr>
  <tr>
   <td colspan="4" background="images/template.slice.17.png"> </td>
   <td><img src="images/spacer.gif" width="1" height="37" border="0" alt="" /></td>
  </tr>
  <tr>
   <td colspan="4" align="center" valign="top" background="images/template.slice.18.png" style="vertical-align:top;"><p class="standard"> </p>
     <table width="80%" border="0">
      <tr>
        <td colspan="2">
          <?php
          	if($messages){
			//displayErrors($messages);
		} else {
			//echo("<p align=\"center\" class=\"standard\">Your account has been activated.</p><p align=\"center\" class=\"standard\">You now need to change your password. If you like you can also change your username, Remember that you only have 3 days to do so and this change will be permanent.</p>");
	?></td>
        </tr>
      <form name="ChangeDetails" method="post" action="<?=$_SERVER['PHP_SELF']?>">
      <input type="hidden" name="activationid" value="<?php if($_GET['id']){ $id=$_GET['id']; echo($id); } elseif($_POST['activationid']){ $id=$_POST['activationid']; echo($id); } else { die("No ID") } ?>" />
      <tr>
        <td width="50%"><div align="right" class="standard">New Username: </div></td>
        <td width="50%"><input name="login" type="text" id="login" size="35" maxlength="30" /></td>
      </tr>
      <tr>
        <td><div align="right" class="standard">New Password:</div></td>
        <td><input name="password" type="password" id="password" size="35" maxlength="30" /></td>
      </tr>
      <tr>
        <td><div align="right" class="standard">Re-enter password:</div></td>
        <td><input name="passwordc" type="password" id="passwordc" size="35" maxlength="30" /></td>
      </tr>
      <tr>
        <td><div align="right" class="standard">Please enter the code: </div></td>
        <td>
		<?php
			require_once('recaptchalib.php');
			$publickey = "6Le4fsESAAAAAKMOHb8aaiyDfGRJyr0y0EU7dXm-"; // you got this from the signup page
			echo recaptcha_get_html($publickey);
            ?>
        </td>
      </tr>
      <tr>
        <td> </td>
        <td><input type="submit" name="submit" id="submit" value="Change your details" /></td>
      </tr>
      </form>
    </table>
     </td>
   <td><img src="images/spacer.gif" width="1" height="450" border="0" alt="" /></td>
  </tr>
  <tr>
   <td colspan="4" background="images/template.slice.19.png"> </td>
   <td><img src="images/spacer.gif" width="1" height="50" border="0" alt="" /></td>
  </tr>
  <tr>
   <td colspan="9" background="images/template.slice.20.png"> </td>
   <td><img src="images/spacer.gif" width="1" height="40" border="0" alt="" /></td>
  </tr>
</table>
</div>
</body>
</html>
<?php
} ?>

 

Thanks to all you kind people that take your time to read and help me with this problem. I'm sorry if it is a really simple problem I missed out that makes me look like a right idiot and wasted your time, but that's me I'm always missing stuff out like that, I do proof read though just sometimes not good enough.

 

Thanks in advance!

If there's a 500 error then the web server logged it. What do the logs say?

 

Thanks for your reply, I completely forgot about the logs.

 

The log is saying there is a parse error, I found it and fixed it. I can't believe I missed a semi-colon on line 158, Yet when I take the code hinted out it works fine, No errors thrown. Very weird.

 

I got it fixed, Thanks for taking your time to read! :P

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.