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

foreach help.
Hello all,

First time I'm attempting to use a foreach statement and was just wondering if my

Number Format
Hi All,

I have number '000000000050085' I want to format it to 500.85 Can any one give me

breaking a text file into paragraphs based on strings
I have a text file of email addresses that is all squished together. It looks like this:

abc

MySql timezone
Code: $sql = "SELECT *, date_format(date, '%m/%d/%Y at %I:%i %p' )as date FROM comments WHERE t

Thread in PHP
Thread in PHP
Some basic use and basic code for thread in php
This is my question?

Script not running properly
Hello Everyone
This is a basic script for posting to a database. I'm not sure why it doesn't work

Why do I get this error?
Error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or

Tracking Unique Clicks
Hi guys and gals,

Basically I have a database which tracks clicks on my outbound links, I do

Help a newbee save my job !
Hey guys i am dying here i am new to php and would like for someone to help me with this problem

PHP FTP connect doesn't work with correct login
Hi!

i am working on this test code:
Quote<?php

$ftp_ser

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