KDM Posted April 25, 2011 Share Posted April 25, 2011 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"; } ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 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"; } ?> Quote Link to comment Share on other sites More sharing options...
KDM Posted April 25, 2011 Author Share Posted April 25, 2011 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. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 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] Quote Link to comment Share on other sites More sharing options...
KDM Posted April 25, 2011 Author Share Posted April 25, 2011 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" Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 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 Quote Link to comment Share on other sites More sharing options...
KDM Posted April 25, 2011 Author Share Posted April 25, 2011 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 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 It was supposed to be // to indicate the start of a comment . . . Quote Link to comment Share on other sites More sharing options...
KDM Posted April 25, 2011 Author Share Posted April 25, 2011 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 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 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. Quote Link to comment Share on other sites More sharing options...
KDM Posted April 25, 2011 Author Share Posted April 25, 2011 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> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 25, 2011 Share Posted April 25, 2011 You need to do the strlen() comparisons before hashing the value. MD5() produces a 32 character hash, so it will always fail that comaprison. Quote Link to comment Share on other sites More sharing options...
KDM Posted April 26, 2011 Author Share Posted April 26, 2011 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"; } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.