Hi everyone,
I am making a quiz using forms. The user answers by clicking on radio type buttons e.g.

<input type="radio" name="question1" value="whatever1">
<input type="radio" name="question1" value="whatever2">
<input type="radio" name="question1" value="whatever3">

I collect the answer on the second page using something like

$answer1=$_POST['question1'];

Now the problem: If the user doesn't answer at all i get something like
Notice: Undefined index: question1 in c:\......

What can I do to prevent this?
thanks a lot!

Hi everyone,
I am making a quiz using forms. The user answers by clicking on radio type buttons e.g.

<input type="radio" name="question1" value="whatever1">
<input type="radio" name="question1" value="whatever2">
<input type="radio" name="question1" value="whatever3">

I collect the answer on the second page using something like

$answer1=$_POST['question1'];

Now the problem: If the user doesn't answer at all i get something like
Notice: Undefined index: question1 in c:\......

What can I do to prevent this?
thanks a lot!

if empty($_POST['question1']){
  die(" Please Select an option.");
}
 
else{
 .....process the form
}

and one quick suggestion:
why not use the css along with the error messages to give a good impression.

http://www.happyjunction.com

if empty($_POST['question1']){
  die(" Please Select an option.");
}
 
else{
 .....process the form
}

You've got a syntax error there.

if (empty($_POST['question1'])) {
  die(" Please Select an option.");
}
 
else{
 //.....process the form
}

Off topic:
Use your signature for links to your site. The mods may be cruel. :)

You've got a syntax error there.

if (empty($_POST['question1'])) {
  die(" Please Select an option.");
}
 
else{
 //.....process the form
}

Off topic:
Use your signature for links to your site. The mods may be cruel. :)

yes thanks for pointing the mistake.

This question has already been answered. Start a new discussion instead.