leest Posted January 2, 2008 Share Posted January 2, 2008 I have an if else query i have worked through a tutorial to try and get the structure correct, however when i run the test script i get errors. I know the query works but when placed in the if else statement i get an error on line 22 which is $candidate_id = $_GET["candidate_id"]; the whole script and error message are shown below. Any guidance would be appreciated, thanks. include '../folder1/folder2/db1.php'; $username = $_SESSION['username']; $SID = $_SESSION['SID']; $query = "SELECT username FROM candidate WHERE username ='$username' AND site_id ='$SID'"; $result = mysql_query($query)or die(mysql_error()); $num = mysql_num_rows($result); //will be either 0 if its not there or more than zero if it is if($num > 0) { //checks for an entry //***** Gets Candidate ID from candidate table *************// $username = $_SESSION['username']; $query = "SELECT * FROM candidate WHERE username ='$username'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); $candidate_id = $row['candidate_id']; } elseif ( $candidate_id = $_GET["candidate_id"]; $query = "SELECT username FROM candidate_joborder WHERE username ='$username' AND candidate_id ='$candidate_id'"; $result = mysql_query($query)or die(mysql_error()); $num = mysql_num_rows($result); //will be either 0 if its not there or more than zero if it is if($num > 0) { //checks for an entry// ) else echo "test"; The error "Parse error: syntax error, unexpected ';' in /public_html/search/test.php on line 22" Quote Link to comment https://forums.phpfreaks.com/topic/84079-if-else-error/ Share on other sites More sharing options...
rajivgonsalves Posted January 2, 2008 Share Posted January 2, 2008 first of all you have to have the { braces instead of the ( braces... secondly the line throwing the errors is elseif now you are specifying a elseif but not specifiying a condition.... also please block all your if statements if they are one liners also it leads to much readable code... hopes it helpful... Quote Link to comment https://forums.phpfreaks.com/topic/84079-if-else-error/#findComment-427977 Share on other sites More sharing options...
leest Posted January 2, 2008 Author Share Posted January 2, 2008 Thank you, I will make the changes and hopefully it will solve my problems. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/84079-if-else-error/#findComment-427980 Share on other sites More sharing options...
rajivgonsalves Posted January 2, 2008 Share Posted January 2, 2008 Your welcome I would of re-written your code but I do not know which if statement should end where Quote Link to comment https://forums.phpfreaks.com/topic/84079-if-else-error/#findComment-427981 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.