Jump to content

I keep getting an unexpected T ELSE error with my register script


KDM

Recommended Posts

The error is on line 101. Help please.

 

<?php
//begin register script

$submit = $_POST['submit'];


//form data
$username= strip_tags ($_POST['username']);
$email= strip_tags($_POST['email']);
$pwd= strip_tags($_POST['pwd']);
$confirmpwd= strip_tags($_POST['confirmpwd']);
$date = date("Y-m-d");


if ($submit)
{

//check for required form data
if($username&&$pwd&&$confirmpwd&&$email)
{
//encrypt password
$pwd = md5($pwd);
$confirmpwd =md5($pwd);

//check if passwords match
if ($pwd==$confirmpwd)
{
//check length of username
if (strlen($username)>25||strlen($username)>25)
{
	echo "length of username is too long";
}
else
{
//check password length
if(strlen($pwd)>25||strlen($pwd)<6)
{
	echo"password must be between 6 and 25 characters";
}
else
{
	//register the user
}

else
	echo "your passwords do not match";
}
else
echo "please fill in all fields";

}
?> 

 

There is no line 101 in that code, but you're missing 2 closing curly braces. If you indent the code properly, it makes those errors easier to find.

 

<?php
//begin register script

$submit = $_POST['submit'];

//form data
$username= strip_tags ($_POST['username']);
$email= strip_tags($_POST['email']);
$pwd= strip_tags($_POST['pwd']);
$confirmpwd= strip_tags($_POST['confirmpwd']);
$date = date("Y-m-d");

if ($submit) {
   //check for required form data
   if($username&&$pwd&&$confirmpwd&&$email) {
      //encrypt password
      $pwd = md5($pwd);
      $confirmpwd =md5($pwd);

      //check if passwords match
      if ($pwd==$confirmpwd) {
         //check length of username
         if (strlen($username)>25||strlen($username)>25) {
            echo "length of username is too long";
         } else {
            //check password length
            if(strlen($pwd)>25||strlen($pwd)<6)
            {
               echo"password must be between 6 and 25 characters";
            } else {
               //register the user
            } else {
               echo "your passwords do not match";
            } else {
               echo "please fill in all fields";
            }
?>

2 curly brackets where? I tried your code and I get this error.

Parse error: syntax error, unexpected T_ELSE in /home/content/13/6987913/html/new/register.php on line 88

 

I want to know when to use curly brackets.  It's confusing to me.

 

I didn't edit your code other than to change it's structure, so whatever errors were there are still there. You should use an editor that supports syntax highlighting, and bracket matching to help you spot these types of errors. For more on control structures, see the manual section on that topic. Probably a good idea to avoid the alternative syntax until you have a good grasp of the conventional syntax . . .

 

This code has no further parse errors.

<?php
//begin register script

$submit = $_POST['submit'];

//form data
$username= strip_tags ($_POST['username']);
$email= strip_tags($_POST['email']);
$pwd= strip_tags($_POST['pwd']);
$confirmpwd= strip_tags($_POST['confirmpwd']);
$date = date("Y-m-d");

if ($submit) {
   //check for required form data
   if($username&&$pwd&&$confirmpwd&&$email) {
      //encrypt password
      $pwd = md5($pwd);
      $confirmpwd =md5($pwd);
      //check if passwords match
      if ($pwd==$confirmpwd) {
         //check length of username
         if (strlen($username)>25||strlen($username)>25) {
            echo "length of username is too long";
         } else {
            //check password length
            if(strlen($pwd)>25||strlen($pwd)<6) {
               echo"password must be between 6 and 25 characters";
            } else {
               //register the user
            }
         }
      } else {
         echo "your passwords do not match";
      }
   } else {
      echo "please fill in all fields";
   }
}
?>

[/code]

yea I tried bringing the code into netbeans but I don't know how to use it.  The code you provided is error free, but the form doesn't work how it's supposed to. Even when my passwords match this is being printed in the browser

 

"your passwords do not match"

If that's being echoed, then the passwords don't match somehow. Make this edit to see exactly what the $_POST array holds after the form is submitted, and we'll go from there.

 

$submit = $_POST['submit'];

echo '<pre>'; print_r($_POST); echo '</pre>'; // <--- add this

//form data

Is this right?

<?php
//begin register script

$submit = $_POST['submit'];

echo '<pre>'; print_r($_POST); echo '</pre>'; / <--- add this

 

I got this error

Parse error: syntax error, unexpected '/' in /home/content/13/6987913/html/new/register.php on line 62

Now I see the problem.

$pwd = md5($pwd);
$confirmpwd =md5($pwd); // <--- Should be md5($confirmpwd);

 

There's really no reason to use strip_tags(), or any escaping, etc. on data that will be hashed, BTW. In fact, in most cases you're better off to do nothing at all to it before hashing it. What if the user wants to use "thisIsMy<Password>" as their password? It would be accepted, but silently altered, and the user wouldn't be able to log in.

Ok I changed that. I don't get the passwords do not match message anymore.  Now when I type in the password and it is 6 characters, it still tells me that my password must be 6 to 25 characters.  Here is my form.  Is this info correct?

   	<form action="register.php" method="POST"> 
    <table width="358" border="0" align="center">
  <tr>
    <td width="113">username</td>
    <td width="235"><input name="username" type="text" maxlength="25" /></td>
    </tr>
  <tr>
    <td>email</td>
    <td><input name="email" type="text" /></td>
    </tr>
  <tr>
    <td>password</td>
    <td><input name="pwd" type="password" /></td>
    </tr>
  <tr>
    <td>confirm password</td>
    <td><input name="confirmpwd" type="password" /></td>
    </tr>
  <tr>
    <td></td>
    <td><label>
      <input type="submit" name="submit" id="submit" value="submit" />
    </label></td>
    </tr>
</table>
</form>

 

Thanks everything seems to be working so far.  I made the suggested changes.  Here is my working code.

<?php
//begin register script

$submit = $_POST['submit'];

//form data
$username= strip_tags ($_POST['username']);
$email= strip_tags($_POST['email']);
$pwd= strip_tags($_POST['pwd']);
$confirmpwd= strip_tags($_POST['confirmpwd']);
$date = date("Y-m-d");

if ($submit) {
   //check for required form data
   if($username&&$pwd&&$confirmpwd&&$email) {
   
   
	//check length of username
        if (strlen($username)>25||strlen($username)<6) {
            echo "username must be bewteen 6 and 25 characters";
        } else {

        //check password length
        if (strlen($pwd)>25||strlen($pwd)<6) {
            echo"password must be between 6 and 25 characters";
            } else {
               
    //register the user
            }
	 }
         
      //encrypt password
      $pwd = md5($pwd);
      $confirmpwd = md5($confirmpwd);
  
      //check if passwords match
      if ($pwd==$confirmpwd) {
    
      } else {
         echo "your passwords do not match";
      }
      } else {
      echo "please fill in all fields";
   }
}
?>

 

 

 

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.