Welcome Guest, Not a member yet? Register   Sign In
Undefined offset
#1

[eluser]PHP Creative[/eluser]
The following script checks to see if the user answer matches the correct answer.


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)

$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.


Code:
foreach ($this->input->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++;
}


Messages In This Thread
Undefined offset - by El Forum - 12-13-2009, 12:13 PM
Undefined offset - by El Forum - 12-13-2009, 02:53 PM
Undefined offset - by El Forum - 12-13-2009, 05:21 PM
Undefined offset - by El Forum - 12-13-2009, 06:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB