Value 0 on radio button should not be null

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
Guys,

I have a form and a few radio buttons, the value of this radio buttons is 1 and three 0s.

The Value of the buttons are like this, when clicked.

Button 1 =0
Button 2 =1
Button 3 =0
Button 4 =0

I equate my varibales like this to get the value from the radio buttons

$question1 = $_POST['question1'];

The program is ok if i choose radio button 2 because the value is 1 but if i choose the other radio buttons like 1,3 & 4. there will be an error like

Notice: Undefined index: question1 in c:\inetpub\wwwroot\eval\MSWpre1.php on line 28

Please help, thanks.
 
Do you have your radio buttons in the same 'group' !? Like this:
Code:
<input name="question1" type="radio" value="0" checked>
<input name="question1" type="radio" value="1">
<input name="question1" type="radio" value="0">
<input name="question1" type="radio" value="0">
I mean, they should have the same name...it´s that what you have !?

Gesf
 
better use:

Button 1 =2
Button 2 =1
Button 3 =2
Button 4 =2

and compare:

if (isset($button)) {Echo"sorry";}
elseif ($button==1)
{
code here
}
else
{
code here
}
 
Yeh, WiZARD is right! You can use names instead too:
Code:
<input name="question1" type="radio" value="Zero" checked> 
<input name="question1" type="radio" value="One"> 
<input name="question1" type="radio" value="Zero"> 
<input name="question1" type="radio" value="Zero">
And than:
Code:
<?php

f (isset($_POST['question1'])){
  if ($_POST['question1'] == 'One'){ 
    // Do what you need
  } 
  else{ 
   //  Do what you need
  }
}

?>

Gesf
 
Back
Top