Snooble Posted March 3, 2007 Share Posted March 3, 2007 <?php elseif($_SESSION['points1'] == 1){ header("Location: cheater.php"); } ?> make sense? futher down the page i set $_SESSION['points1'] to 1 using $_SESSION['points1'] = 1; so when i refresh the page it should take me to "cheater.php" shouldn't it? Thanks, Snooble Quote Link to comment https://forums.phpfreaks.com/topic/41021-trouble-with-if-statement/ Share on other sites More sharing options...
wildteen88 Posted March 3, 2007 Share Posted March 3, 2007 An if/else or if/elseif/else statement must start with if first. Also if you are using sessions you must start the session first. Otherwise the session variables will not work. So you code should be: <?php session_start(); if($_SESSION['points1'] == 1){ header("Location: cheater.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/41021-trouble-with-if-statement/#findComment-198637 Share on other sites More sharing options...
Snooble Posted March 3, 2007 Author Share Posted March 3, 2007 <?php include 'sessionstartandsql.php'; include 'expire.php'; if(!isset($_SESSION['username'])){ header("Location: mustlogin.php"); } elseif($_SESSION['points1'] == 1){ header("Location: cheater.php"); } $_SESSION['point'] = "".rand(0, 10).".".rand(0, 9)."".rand(0, 9).""; echo "You Scored:".$_SESSION['point']." points"; $result = $list['point'] + $_SESSION['point']; echo "Your Total Points Are: ". $result; $_SESSION['points1'] = 1; $sql = "UPDATE wmusers SET point = '$result' WHERE username = '".$list['username']."' LIMIT 1"; mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); ?> full script. Apologies, session start's within the included files. Snooble Quote Link to comment https://forums.phpfreaks.com/topic/41021-trouble-with-if-statement/#findComment-198639 Share on other sites More sharing options...
papaface Posted March 3, 2007 Share Posted March 3, 2007 replace elseif with if Also you still dont have session_start() at the top of your page to register the sessions. Quote Link to comment https://forums.phpfreaks.com/topic/41021-trouble-with-if-statement/#findComment-198652 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.