Andrew R Posted December 13, 2009 Share Posted December 13, 2009 The following script checks to see if the user answer matches the correct answer. Form Fields are set up the following way... user_answer[$i] | value = a user_answer[$i] | value = b user_answer[$i] | value = c all radio fields (above) orgid[$i] | value = $i answer[$i] | value = (a or b, c) all hidden fields (above) $i = question id/number Basically when question answer isn't selected an undefined offset error message is generated. Adding if empty or isset messes up the order. foreach ($_POST['orgid'] as $k =>$v) { $orgid[$k] = $v; } $k = 0; $m = 0; while ($k <= 19) { if ($_POST['user_answer'][$k] == $_POST['answer'][$k]) { $correct++; unset ($_POST['user_answer'][$k]); unset ($orgid[$k]); } else { $incorrect++; } $k++; } Any ideas/suggestions? Thanks a million Link to comment https://forums.phpfreaks.com/topic/185009-undefined-offset/ Share on other sites More sharing options...
Buddski Posted December 14, 2009 Share Posted December 14, 2009 I dont see why this wouldnt work.. <?php foreach ($_POST['orgid'] as $k =>$v) { $orgid[$k] = $v; } $k = 0; $m = 0; while ($k <= 19) { if (isset($_POST['user_answer'][$k]) && $_POST['user_answer'][$k] == $_POST['answer'][$k]) { $correct++; unset ($_POST['user_answer'][$k]); unset ($orgid[$k]); } else { $incorrect++; } $k++; } ?> Link to comment https://forums.phpfreaks.com/topic/185009-undefined-offset/#findComment-976667 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.