表单提交后,PHP ::单选按钮值始终设置为“打开”
问题描述:
Here is my form:
<form method="post" enctype="multipart/form-data">
<input type="radio" name="sex" value="male" checked />
<input type="radio" name="sex" value"female"/>
<input type="submit" name="btn">
</form>
$_POST['sex'] = always I see the below output for the radio button:
See = string 'on'
It always gives "on" instead of male or female. This is what I have put in the form.
Am I doing something wrong here?
Please help.
If I use SELECT box, then it works well. But I need to make it work using radio button.
这是我的表格: p>
&lt; form method = “post”enctype =“multipart / form-data”&gt;
&lt; input type =“radio”name =“sex”value =“male”checked /&gt;
&lt; input type =“radio”name =“sex “value”female“/&gt;
&lt; input type =”submit“name =”btn“&gt;
&lt; / form&gt;
code> pre>
$ _ POST [ 'sex'] =总是我看到单选按钮的下面输出: p>
请参阅=字符串'on' p>
它始终显示“on” 而不是男性或女性。 这就是我在表格中提出的内容。 p>
我在这里做错了吗? p>
请帮忙。 p>
如果我使用SELECT框,那么效果很好。 但我需要使用单选按钮使其工作。 p>
div>
答
<form method="post" enctype="multipart/form-data">
Male : <input type="radio" name="sex" value="male" checked /><br/>
Female : <input type="radio" name="sex" value="female"/><br/>
<input type="submit" name="btn">
</form>
<?php
error_reporting(0);
echo $_REQUEST['sex'];
?>
Above code is working, Changes
value = female
you forgot to add = sign
答
<input type="radio" name="sex" value="female"/>
you didn't put equal to sign near female.