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";

}
?> 

 

Link to comment
Share on other sites

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";
            }
?>

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

wow neat trick. it printed this in the browser

Array
(
    [username] => ljk1181
    [email] => dhshd`
    [pwd] => ljkjr5000
    [confirmpwd] => ljkjr5000
    [submit] => submit
)
your passwords do not match

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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";
   }
}
?>

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.