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 } Link to comment https://forums.phpfreaks.com/topic/158686-solved-syntax-in-for-loop/ 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 } Link to comment https://forums.phpfreaks.com/topic/158686-solved-syntax-in-for-loop/#findComment-836914 Share on other sites More sharing options...
galvin Posted May 19, 2009 Author Share Posted May 19, 2009 THAT did it, thanks Masna! Link to comment https://forums.phpfreaks.com/topic/158686-solved-syntax-in-for-loop/#findComment-836916 Share on other sites More sharing options...
Masna Posted May 19, 2009 Share Posted May 19, 2009 No problem! Link to comment https://forums.phpfreaks.com/topic/158686-solved-syntax-in-for-loop/#findComment-836917 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.