guys Ive got a simple problem, im designing an online questionnaire and on submission the coding that I have used to validate whether a user has filled in all the questions is supposed to identify any questions they have missed out and print out a simple error message.
It correctly identify which questions have not been filled in but returns the following error message too:
Notice: Undefined index: 1 in c:\Project\htdocs\dissertation\v41\questionnaire.p hp on line 118.
Notice: Undefined index: 1 in c:\Project\htdocs\dissertation\v41\questionnaire.p hp on line 119
Notice: Undefined index: 2 in c:\Project\htdocs\dissertation\v41\questionnaire.p hp on line 118
Notice: Undefined index: 2 in c:\Project\htdocs\dissertation\v41\questionnaire.p hp on line 119
.
.
This repeats for all the questions that are not filled in (NULL)!!!
[PHP] ///////////////////////////////////////////////////////////////////////////////////
////////////////////////VALIDATE THE QUESTIONS ANSWERS////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// Validate the The Insertion of all answers -- check that they dont equal NULL
// Query all the answers
$check_answers = "SELECT question_id FROM questions as qid ORDER BY question_id ASC";
$check_answers_result = @mysql_query($check_answers);
// Loop all the questions and check that answers were submitted
while ($row = mysql_fetch_array($check_answers_result,MYSQL_BOTH )) {
$qid = $row[0]; // Set the $Question_id which is assigned here to $qid to record 0
// Check all the answers given match the following
if (!empty($_REQUEST['item[$qid]'])) {
$item[$qid] = $_REQUEST['item[$qid]'];
if ($item[$qid] =='1') { //answer = 1
$score1 = '1';
} elseif ($item[$qid] == '2') { //answer = 2
$score1 = '2';
} elseif ($item[$qid] == '3') { //answer = 3
$score1 = '3';
} elseif ($item[$qid] == '4') { //answer = 4
$score1 = '4';
} elseif ($item[$qid] == '5') { //answer = 5
$score1 = '5';
} elseif ($item[$qid] == '6') { //answer = 6
$score1 = '6';
} elseif ($item[$qid] == '7') { //answer = 7
$score1 = '7';
} elseif ($item[$qid] == '0') { //answer = N/A
$score1 = '0'; //answer = 7
}
} else { //$_REQUEST['question1'] is not set.
$item[$qid] == NULL;
$errors[] = "<center><font color=blue>In Section 2:</font> You forgot to make a selection for <font color=red>Q".$item[$qid]."!</font></center>";
}
}[/PHP]
The questionnaire is dynamic so there are no predefined number of questions. The problem comes from the else part of the statement from here
[PHP] $item[$qid] == NULL;
$errors[] = "<center><font color=blue>In Section 2:</font> You forgot to make a selection for <font color=red>Q".$item[$qid]."![/PHP]
Any help would be great please
Thanks
Nabeel