The PHP code gets the value of the radio button in the form: (The radio button lets us select only one, there is a "checked" property, which is used by default, which is the default value each time we refresh our page.) )
Cases:
1 <formname= "MyForm"Action=""Method= "POST">2 Gender:3 <inputtype= "Radio"name= "Sex"value= "Male"checked/>male4 <inputname= "Sex"type= "Radio"value= "female" />female5 <inputtype= "Submit"name= "Submit"value= "Submit" />6 </form>
1 <? PHP 2 Echo "Your choice is:"; 3 Echo $_post ["Sex"]; 4 ?>
If you choose a male, then the value is "male", if you choose a female, then the value is "female."
The PHP code gets the value of the check box : (check box is able to let us go to the multi-select, they exist at the same time, in order to facilitate the value we will name to an array.) )
Format: <input type= "checkbox" Name= "chkbox[]" value= "Chkbox1"/>
Method: The Count () function is used in the return page to calculate the size of the array, combined with a For loop statement, to output the selected check box value.
Cases:
1 <formAction=""name= "Form1"Method= "POST">2 the number you like:3 <inputtype= "checkbox"name= "mrbook[]"value= "1" />14 <inputtype= "checkbox"name= "mrbook[]"value= "2" />25 <inputtype= "checkbox"name= "mrbook[]"value= "3" />36 <inputtype= "checkbox"name= "mrbook[]"value= "4" />47 <inputtype= "Submit"name= "Submit"value= "Submit" />8 </form>
1<?PHP2 if($_post[' Mrbook ']!=NULL)3 {4 Echo"The number you selected is:";5 for($i= 0;$i<Count($_post[' Mrbook ']);$i++)6 {7 Echo $_post[' Mrbook '] [$i]." ";8 }9 }Ten?>
How to get the value of a radio button and a check button in a php form