Undefined offset


Posted on 16th Feb 2014 07:03 pm by admin

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.


Code: 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?

No comments posted yet

Your Answer:

Login to answer
303 Like 9 Dislike
Previous forums Next forums
Other forums

How would I protect......
I have a from, actually, a good amount of forms. How can I make it so you can't type the characters:

Edit MySQL Row Using PHP and HTML Form
Hello,

Here's what I'm trying to do. Build a page where a user enters a MySQL row number in.

first id from db not showing
I have a php script which displays the content of a mysql table as a html table with sorting, delete

private constructor
Hello,

Can we create a constructor as private? If yes, what is the use of it? If no, why can'

ereg_replace in Wordpress
Heya - so I'm working on this site: http://world-of-smiles.theportlandco.com/new-patients

The

How can i steam a video on my PHP site? (non YouTube)
Basically I have a PHP site and don't want to give page rank to YouTube. I just want to stream a bas

Contents of variable not echoing
Hey guys, hopefully this is an easy one...

In this line, the variables are not echoing out. T

mr8m - reverse document
Friends,

I'm trying to reverse a document held by MIRO, but it reports the message balan

Query failed issue with php script but works fine in mssql manager!
hi i have the script below which copies data from one table to another but will only insert new data

Parse XML
Good day,

I use oempro software and try to parse XMLReturn but it's not working for me, simpl

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash