galvin Posted May 19, 2009 Share Posted May 19, 2009 Just curious if anything jumps out at anyone as being wrong syntax wise with this code below. I ask because for example, if $_SESSION['answer1'] is NOT set, it is NOT getting set to "wrong" with this code. And therefore, when it redirects to the desired page, $SESSION[answer1'] is still not set to anything. However, for testing purposes, if I actually change the line... $_SESSION['answer$i'] = "wrong"; ...to be... $_SESSION['answer1'] = "wrong"; ...then it IS set to "wrong" after the redirect. In other words, if $i ever equaled "1", it would work. So there must be something wrong with the way the for loop is using my $i variable because it's obviously not getting to the point where it sees $i as the value "1". Any ideas?... if (isset($_POST['submit']) && ($_POST['submit'] == "Stop")) { for ($i=0; $i < 2; $i++) { if (isset($_SESSION['answer$i'])) { //do nothing } else { $_SESSION['answer$i'] = "wrong"; } } redirect_to($_SESSION['currentpage'] . "?quizid=" . $_SESSION['quizid']); } else { // do nothing } Quote Link to comment Share on other sites More sharing options...
Masna Posted May 19, 2009 Share Posted May 19, 2009 Try this instead: if (isset($_POST['submit']) && ($_POST['submit'] == "Stop")) { for ($i=0; $i < 2; $i++) { if (isset($_SESSION['answer'.$i])) { //do nothing } else { $_SESSION['answer'.$i] = "wrong"; } } redirect_to($_SESSION['currentpage'] . "?quizid=" . $_SESSION['quizid']); } else { // do nothing } Quote Link to comment Share on other sites More sharing options...
galvin Posted May 19, 2009 Author Share Posted May 19, 2009 THAT did it, thanks Masna! Quote Link to comment Share on other sites More sharing options...
Masna Posted May 19, 2009 Share Posted May 19, 2009 No problem! Quote Link to comment 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.