treilad Posted July 18, 2006 Share Posted July 18, 2006 Not sure I should go into detail if it's just a syntax error, but I will if needed.The error is:[quote]Parse error: parse error, unexpected T_ELSE in C:\Server\wamp\www\project\index.php on line 17[/quote]Code:[code]<?phpif(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 (!isset($_COOKIE['ID_my_site'])) { header('./logout.php') else{ header('./loginpage.php')}?>[/code]It doesn't like the 'else', but I don't know why. :-/ Quote Link to comment https://forums.phpfreaks.com/topic/14958-whats-wrong-with-this-code/ Share on other sites More sharing options...
wildteen88 Posted July 18, 2006 Share Posted July 18, 2006 You have a missing ; and } after this:[code=php:0]if (!isset($_COOKIE['ID_my_site'])) { header('./logout.php')[/code]it should be:[code=php:0]if (!isset($_COOKIE['ID_my_site'])){ header('./logout.php'); // missing} // missing[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14958-whats-wrong-with-this-code/#findComment-60019 Share on other sites More sharing options...
ChaosXero Posted July 18, 2006 Share Posted July 18, 2006 You're missing a } to end your while loop and your if statement. You need to close your if and while brackets. Quote Link to comment https://forums.phpfreaks.com/topic/14958-whats-wrong-with-this-code/#findComment-60021 Share on other sites More sharing options...
treilad Posted July 18, 2006 Author Share Posted July 18, 2006 Thanks a bunch. :) Quote Link to comment https://forums.phpfreaks.com/topic/14958-whats-wrong-with-this-code/#findComment-60022 Share on other sites More sharing options...
toplay Posted July 18, 2006 Share Posted July 18, 2006 You need a curly right brace before the else. Don't forget semi-colons after each header. And a curly right brace to close off the while loop.Ask yourself why you're checking the cookie variable within the while loop? also if that's the correct form of use of the header() function?Please read some more tutorials on basic PHP syntax and use php.net to help yourself learn what header() does. I think you meant to use include/require. Quote Link to comment https://forums.phpfreaks.com/topic/14958-whats-wrong-with-this-code/#findComment-60026 Share on other sites More sharing options...
dptr1988 Posted July 18, 2006 Share Posted July 18, 2006 What about the indenting? It looks like the else should be for the first If statement, which would mean that the first if statment, the while loop, and the second if statement have not been closed. Quote Link to comment https://forums.phpfreaks.com/topic/14958-whats-wrong-with-this-code/#findComment-60028 Share on other sites More sharing options...
treilad Posted July 18, 2006 Author Share Posted July 18, 2006 I meant to header, because this is just a script to check the credentials of the user. Each page loads it automatically (ideally, anyway. working on that.) to check their credentials, and if they check out, they can view the page.EDIT:I said that wrong. I have this at the top of each page. It checks their credentials and if they check out, it does nothing. If the credentials don't match, it removes the cookie because they have a cookie set but their credentials don't match, so they don't keep the cookie. If there isn't a cookie, it boots them from the page to the login page.Also, now I'm getting this error:[quote]Parse error: parse error, unexpected $end in C:\Server\wamp\www\project\index.php on line 204[/quote]204 is the end. Nothing there, so I assume I'm missing something. Quote Link to comment https://forums.phpfreaks.com/topic/14958-whats-wrong-with-this-code/#findComment-60030 Share on other sites More sharing options...
wildteen88 Posted July 18, 2006 Share Posted July 18, 2006 You are missing closing } or ) if you are getting that error. Go through you code making sure your } and ) pair up. Quote Link to comment https://forums.phpfreaks.com/topic/14958-whats-wrong-with-this-code/#findComment-60036 Share on other sites More sharing options...
redarrow Posted July 18, 2006 Share Posted July 18, 2006 <?phpif(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 (!isset($_COOKIE['ID_my_site'])) { header('./logout.php') }else{ header('./loginpage.php')} }?> Quote Link to comment https://forums.phpfreaks.com/topic/14958-whats-wrong-with-this-code/#findComment-60040 Share on other sites More sharing options...
treilad Posted July 18, 2006 Author Share Posted July 18, 2006 It didn't like yours, redarrow. :( But I got it to work with wildteens tip.Also, the code cleared up. No more errors. But I can still visit the page when I'm logged out. I have include('index3.php'); which is the code I just fixed at the top of index.php. Before I make another topic, I'll just put it here and see if there's a simple answer. I need the code to ensure that the page is not visible if the user's credentials do not match up. For some reason it doesn't header me anywhere even when I'm not logged in, as it should. Again, here's my "corrected" code:[code]<?phpinclude ('db.php');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 (!isset($_COOKIE['ID_my_site'])) { header('./logout.php'); }}}else{ header('./loginpage.php');}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14958-whats-wrong-with-this-code/#findComment-60050 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.