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

connect() succeeds but accept() does not?
Please help me with this problem. I'm working on a time-sensitive project where I'm using TCP socket

LinkedList help
Ok so I just learned quickly about lists, so I have a not too hard project I think, but am having a

sapgui f4 help last search
I know this has to be simople. One user (maybe more) does not have the "last search saved" from the

Preventing SQL Injection
I have a question about SQL Injection, In some of our code we use this: view plaincopy to clipboa

Replacing a string on click of a button
Hi! Is there a way to replace a string on a click of a text link?

This is what I've come up w

Do not allow posting of whitespace
Currently the script below works if the user does not type a name/message, but if i create a whitesp

Basic Question about Threading and PHP...
I have a page that I am working on and it is taking several hours to process. The basics of what th

how to populate a drop down box
Hi buddies!

PROCEDURE DOWNLOAD_REPORT_FORM (report_name varchar) is begin DOWNLO

Multiple forms on the same page (safari)
Hello everyone,

I have 3 forms on the same page, that opens in a new window and submits to a

How to have a log of all the status a VIM document had been ?
Hi guys,

I’m using SAP Invoice Management plugin and the /OPT/VIM_ANALYTICS transa

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