SkyRanger Posted April 8, 2009 Share Posted April 8, 2009 I am having a syntax problem and not sure what the problem is. Can somebody please have a look and let me know what the problem is: if(isset($_POST['Recover'])) { if($username == $_POST['username']){ mysql_connect("localhost", "username", "pass") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $result = mysql_query("SELECT * FROM admin where username = '$username'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { echo $row['email']; //just a test to ensure database connects } elseif($username == '') { echo "That username is not found in our database"; } } else { ?> <form The Error I am getting is: Parse error: syntax error, unexpected T_ELSEIF in /home/esscal/public_html/admin/recover.php on line 28 Line 28 is: } elseif($username == '') { Quote Link to comment https://forums.phpfreaks.com/topic/153213-solved-if-elseif-syntax-problem/ Share on other sites More sharing options...
Maq Posted April 8, 2009 Share Posted April 8, 2009 Need another '}', the first one is for the while loop but you don't have a terminating curly for the if. } } elseif($username == '') { Quote Link to comment https://forums.phpfreaks.com/topic/153213-solved-if-elseif-syntax-problem/#findComment-804844 Share on other sites More sharing options...
kenrbnsn Posted April 8, 2009 Share Posted April 8, 2009 If you clean up your indentation, you will see the error. You don't end the "if" block before you do the "elseif" Ken Quote Link to comment https://forums.phpfreaks.com/topic/153213-solved-if-elseif-syntax-problem/#findComment-804846 Share on other sites More sharing options...
SkyRanger Posted April 8, 2009 Author Share Posted April 8, 2009 Awesome, I see it now, thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/153213-solved-if-elseif-syntax-problem/#findComment-804852 Share on other sites More sharing options...
Maq Posted April 8, 2009 Share Posted April 8, 2009 Like Ken mentioned, with proper indentation and format this error could have been easily avoided or detected. Quote Link to comment https://forums.phpfreaks.com/topic/153213-solved-if-elseif-syntax-problem/#findComment-804855 Share on other sites More sharing options...
SkyRanger Posted April 9, 2009 Author Share Posted April 9, 2009 Yeah, I fixed allot of that mess, but I found a new problem which I cannot figure out how to fix. I am still a noob with php scratching my way through code with allot of research and trial and error. I can get it to work with a proper username that is stored in the DB but not when I put none or the wrong one, It keeps coming up with the error: Notice: Undefined variable: adminuser in /home/esscal/public_html/admin/recover.php on line 29 Line 29 is: if($username == $adminuser){ Below is the full code: if(isset($_POST['Recover'])) { $username = $_POST['username']; mysql_connect("localhost", "uname", "pwrd") or die(mysql_error()); mysql_select_db("dbase") or die(mysql_error()); $result = mysql_query("SELECT * FROM admin where username = '$username'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $adminuser = $row['username']; //just a test to ensure database connects } if($username == $adminuser){ echo "Username Correct"; } elseif($username == '') { echo "That username is not found in our database"; } } else { ?> <form Quote Link to comment https://forums.phpfreaks.com/topic/153213-solved-if-elseif-syntax-problem/#findComment-805106 Share on other sites More sharing options...
Maq Posted April 9, 2009 Share Posted April 9, 2009 Well if your query doesn't match a username then the variables adminuser will never be assinged to anything because $row['username'] never exists. You should do a check to see if any rows are returned: if(mysql_num_rows($result) == 0) { echo "Error no matches for that username"; } else { $adminuser = $row['username']; // Proceed with rest of code . . . } Quote Link to comment https://forums.phpfreaks.com/topic/153213-solved-if-elseif-syntax-problem/#findComment-805112 Share on other sites More sharing options...
SkyRanger Posted April 9, 2009 Author Share Posted April 9, 2009 Works perfect. Thanks Maq Quote Link to comment https://forums.phpfreaks.com/topic/153213-solved-if-elseif-syntax-problem/#findComment-805138 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.