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?

303 Like 9 Dislike
Previous php-forum Next php-forum
Other php-forum

writing a screen scraper
Hello,

I'm writing a screen scraper application and want to be able to get absolute addresses

Is there a more efficient way to code this than what I have?
I have three associative arrays.

$combinedSettings
$userSettings
$defaultSettings

Displaying returned XML in another PHP page
I have an online payment form that will return XML given if a payment is successful or declines. I

How to make URL loads only on login
On my page, when a user login he's redirects to user_home.php. I made it also to open the chat scree

problem in pagination when processing with selectbox form
Hi,

I have a search form, with select boxes, if am selecting the value from the form, it work

Unexpected T_Variable ?
Hi all,
I dont really know what I am doing!! I know I'm doing something wrong, and I know its on

Generate PDF
Hi guys,

I would like to know if there is a way to generate pdf when clicking on a link. In f

modifying a property of an object from a different class
I have 2 classes:
- Math
- Distance

in my math class, I have this line:
$distance =

Check Date/Time in PHP
What I need the code to check is that $reQuest is 24 hours in the past then return a time based on h

Could Someone Please Debug This?
I was wondering if someone could debug this script for me. I realize it's not the tidest script (and

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