georgebates Posted November 28, 2009 Share Posted November 28, 2009 I have another problem, when i run this code i get this error "Parse error: syntax error, unexpected T_ELSE in /home/a1408362/public_html/admin.php on line 41". I can't see why in the code below i get this. Heres the code " <?php //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { } $username = $_COOKIE['ID_my_site']; if ($username <> "administrator"); { header("Location: login.php"); } else {} ?> Quote Link to comment https://forums.phpfreaks.com/topic/183184-problem/ Share on other sites More sharing options...
Alex Posted November 28, 2009 Share Posted November 28, 2009 You shouldn't have a semicolon at the end of this line: if ($username <> "administrator"); Quote Link to comment https://forums.phpfreaks.com/topic/183184-problem/#findComment-966768 Share on other sites More sharing options...
georgebates Posted November 28, 2009 Author Share Posted November 28, 2009 Ok thanks, That worked but now i have same error in another file. Error "Parse error: syntax error, unexpected T_ELSE in /home/a1408362/public_html/members.php on line 48" Code: <?php //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { } $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: login.php"); } //if user is administrator then go to admin view if ($username == "administrator") { header("Location: admin.php"); } //otherwise show admin page else { } //if the cookie does not exist, they are taken to the login screen else{ header("Location: login.php"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/183184-problem/#findComment-966776 Share on other sites More sharing options...
Alex Posted November 28, 2009 Share Posted November 28, 2009 Is that the entire code? The error says line 48 but there's only 37 lines of code there. Quote Link to comment https://forums.phpfreaks.com/topic/183184-problem/#findComment-966777 Share on other sites More sharing options...
georgebates Posted November 28, 2009 Author Share Posted November 28, 2009 i didn't upload the part of the code connecting to my database. I think the problem is in this part: //otherwise show admin page else { } Quote Link to comment https://forums.phpfreaks.com/topic/183184-problem/#findComment-966779 Share on other sites More sharing options...
Alex Posted November 28, 2009 Share Posted November 28, 2009 You should really consider intending your code. It makes it much easier to read and find potential errors. <?php //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { } $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: login.php"); } //if user is administrator then go to admin view if ($username == "administrator") { header("Location: admin.php"); } //otherwise show admin page else { } //if the cookie does not exist, they are taken to the login screen else { header("Location: login.php"); } } ?> Looking at it that way the errors are extremely clear. It seems to me like you mismatched some if statement, I think you want something more like this: <?php //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: login.php"); } //if user is administrator then go to admin view if ($username == "administrator") { header("Location: admin.php"); } //otherwise show admin page else { } //if the cookie does not exist, they are taken to the login screen } } else { header("Location: login.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/183184-problem/#findComment-966791 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.