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.) )
Example: <form name= "MyForm" action= "" method= "POST" >
Gender:
<input type= "Radio" name= "Sex" value= "male" checked/> male <input name= "Sex" type= "Radio" value= "female"/> Female
<input type= "Submit" name= "Submit" value= "Submission"/>
</form>
<?php
echo "Your choice is:";
echo $_post["Sex"];
?>
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.
Example: <form action= "" Name= "Form1" method= "POST" >
The number you like:
<input type= "checkbox" Name= "mrbook[]" value= "1"/>1
<input type= "checkbox" Name= "mrbook[]" value= "2"/>2
<input type= "checkbox" Name= "mrbook[]" value= "3"/>3
<input type= "checkbox" Name= "mrbook[]" value= "4"/>4
<input type= "Submit" name= "Submit" value= "Submission"/>
</form>
<?php
if ($_post[' Mrbook ']!=null)
{
echo "The number you selected is:";
for ($i =0; $i <count ($_post[' Mrbook '); $i + +)
{
echo $_post[' Mrbook ' [$i]. " ";
}
}
?>
How to get the value of a radio button and a check button in a php form