所以我有单选按钮的以下表格。
如何通过PHP获取提交的值?
当我选择男性时,应该打印一条消息success
否则会打印fail
<form action="">
<input type="radio" name="gender" value="male"> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other<br>
<input type="submit" value="submit" name="submit">
</form>
&#13;
答案 0 :(得分:0)
您可以使用isset php API。指导此link to the php docs
答案 1 :(得分:0)
<form method="post">
<input type="radio" name="gender" value="male"> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other<br>
<input type="submit" value="submit" name="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if(isset($_POST["gender"]))
{
$gender = $_POST["gender"];
if($gender == "male")
{
echo "success";
}
else
{
echo "failed";
}
}
else
{
echo "Please choose something";
}
}
?>
输出: - 选择男性时,应该打印消息 成功 否则会打印 失败 ,当你没有选择它时,它应该显示 请选择一些