Jump to content

[SOLVED] help with error in script


ndjustin20

Recommended Posts

I keep getting the "Parse error: syntax error, unexpected T_ELSE in /home/freedom/public_html/register_brandnew.php on line 63" error in this script I am trying to write.  I can't seem to figure out why though.  Any help would be appreciated.

 


<?php

#$page_title = 'New Register Page';

#include('./includes/Header.html');

if(isset($_POST['submitted'])) {

require_once('mysql_connect.php');
$errors = array();

if(empty($_POST['first_name'])) {
$errors[] = 'You forgot to enter your first name';
}else{
$fn = escape_data($_POST['first_name']);
}

if(empty($_POST['last_name'])) {
$errors[] = 'You forgot to enter your last name.';
}else{
$ln = escape_data($_POST['last_name']);
}

if(empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address';
}else{
$e = escape_data($_POST['email']);
}

if(!empty($_POST['password1']) && ($_POST['password1'] == $_POST['password2'])) {
$pw = escape_data($_POST['password1']);
}else{
$errors[] = 'The password you entered and the password confirmation do not match each other.';
}

if(empty($errors)) {
$query = "SELECT userid FROM users WHERE email='$e'";
$result = @mysql_query($query);
$rows = mysql_num_rows($result);

if ($rows > 0) {
echo "I am sorry we can not register you at this time because $e is already taken";
}else{
$npw = SHA('$pw');
$query = "INSERT INTO users ('first_name', 'last_name', 'email', 'password', 'registration_date')
VALUES ('$fn', '$ln', '$e', '$npw', 'NOW()')";
$result = @mysql_query($query);

if($result) {

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);   
   if ((substr($url, -1) == '/') OR
     (substr($url, -1) == '\\') ) {$url = substr ($url, 0, -1);   
   }
   $url .= '/thanks.php';
   header("Location: $url");
   exit();
}else{
$errors[] = 'You could not be registered do to a system error';
$errors[] = mysql_error() . '<br /><br />Query: ' . $query;

}
}else{//[color=pink]THIS IS LINE 63 THIS IS LINE 63 THIS IS LINE 63[/color]
$errors[] = NULL;
}
$page_title = 'Register';
include('./includes/Header.html');

if (!empty($errors)) {
     echo '<h1 id="mainhead">Error!</h1>   
     <p class="error">The following error(s) occurred:<br />';   
     foreach ($errors as $msg) { 
        echo " $msg<br />\n";
     }
     echo '</p><p>Please try again.</p>';
   }

?>
<h1>Register Here</h1>
<form action="register.php" method="post">
<p>First Name<input type="text" name="first_name" value="<?php if(isset($_POST['first_name'])) echo $_POST['first_name'];?>" size="15" maxlength="20" /></p>
<p>Last Name<input type="text" name="last_name" value="<?php if(isset($_POST['last_name'])) echo $_POST['last_name'];?>" size="15" maxlength="20" /></p>
<P>Email Address<input type="text" name="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" size="15" maxlength="20" /></P>
<p>Enter Password<input type="password" name="password1" size="15" maxlength="40" /></p>
<p>Confirm Password<input type="password" name="password2" size="15" maxlength="40" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<p><input type="hidden" name="submitted" value="TRUE" /></p>
</form>
<?php
include('./includes/Footer.html');
?>



Link to comment
https://forums.phpfreaks.com/topic/103308-solved-help-with-error-in-script/
Share on other sites

 

You have two  consecutive else statements

 

}else{
$npw = SHA('$pw');
   ......
   ......
}else{//[color=pink]THIS IS LINE 63 THIS IS LINE 63 THIS IS LINE 63[/color]

 

Also, it looks like there are missing closing braces which may give you more errors

You have two ELSE's on the same IF statement.  Either change the first one to a ELSEIF or fix the bad ELSE

 

if ($rows > 0) {
			echo "I am sorry we can not register you at this time because $e is already taken";
		}else{
			$npw = SHA('$pw');
			$query = "INSERT INTO users ('first_name', 'last_name', 'email', 'password', 'registration_date')
			VALUES ('$fn', '$ln', '$e', '$npw', 'NOW()')";
			$result = @mysql_query($query);

				if($result) {

					$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);   
  						if ((substr($url, -1) == '/') OR
    					(substr($url, -1) == '\\') ) {$url = substr ($url, 0, -1);   
  						}
  				$url .= '/thanks.php';
  				header("Location: $url");
  				exit();
				}else{
					$errors[] = 'You could not be registered do to a system error';
					$errors[] = mysql_error() . '<br /><br />Query: ' . $query;

				}
			}else{//[color=pink]THIS IS LINE 63 THIS IS LINE 63 THIS IS LINE 63[/color]

Thank you very much for your quick replies...I added an elseif statement and am going through and fixing the closing brackets....only 2 weeks into php/mysql so I'm really really new  ;D  Here is the page that I am working on....it's just a place for me to practice the lessons I am taking from mindleaders.com...........http://www.freedomthinking.com/register_brandnew.php

 

I am getting some new errors now but I should be able to get these straightened out.  I looked at those two else statements side by side for like 30 minutes and didn't even enter my mind that that would cause an error  :o

 

thanks again for your help

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.