The PHP radio radio menu gets the code to implement and hold the value

  • 2020-03-31 20:45:39
  • OfStack

PHP reads the radio button radio value
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>php  Read the radio button radio value </title> 
</head> 
<body> 
<form id="form1" name="form1" method="post" action=""> 
<p> 
<label> 
<input type="radio" name="RadioGroup1" value="1" /> 
 The radio </label> 
1<br /> 
<label> 
<input type="radio" name="RadioGroup1" value="2" /> 
 The radio </label> 
2</p> 
<p> 
<label> 
<input type="submit" name="Submit" value=" submit " /> 
</label> 
<br /> 
</p> 
</form> 
</body> 
</html> 
<? 
if( $_POST ) 
{ 
echo ' You chose the single option ',$_POST['RadioGroup1']; 
//Since only one of the radio button properties can be selected at a time, it is OK to simply put their names the same.
} 
?> 

PHP how to keep the value of the radio button method, is the main idea.

<input name="sex" type="radio"value=" male " <?php if($_POST['sex'] != " female ") echo "checked=checked;"?> /> male  
<input type="radio" name="sex" value=" female " <?php if($_POST['sex'] == " female ") echo "checked=checked";?> /> female 
 
In addition, it is recommended not to use Chinese character recognition. It is better to use 0,1 to represent male and female.

Related articles: