为什么这不起作用或我只是愚蠢?它没有打印任何东西,单击按钮后页面看起来完全一样(我有<form>
以及我实际代码中的所有内容)
<html>
<input type="radio" name = "gender" value = "male">
<input type="radio" name = "gender" value = "female">
<input type="radio" name = "race" value = "asian">
<?php
if(isset($_POST["Button"]))
{
if(($_POST["gender"] == "male") && ($_POST["race"] == "asian"))
{
echo "you are male and asian";
}
}
?>
</html>
与它有关的整个代码区域如下所示:
<html>
<center>
<body>
<form method=post action= "">
<br>
<br>
Name: <input type="text" name="username">
<br>
<br>
<br>
I am:
<br>
<br>
<input type="radio" name = "gender" value = "male"> Male
<input type="radio" name = "gender" value = "female"> Female
<br>
<br>
</form>
<form method=post action= "">
Ethnicity:
<br>
<br>
<input type="radio" name = "race" value = "asian">Asian
<br>
<br>
<input type="radio" name = "race" value = "black">Black
<br>
<br>
<input type="radio" name = "race" value = "white">White
<br>
<br>
<br>
<input type="submit" name="Button" value = "Who will I marry?">
</form>
<?php
if(isset($_POST["Button"]))
{
if(($_POST["gender"] == "male") && ($_POST["race"] == "asian"))
{
?>
congrats!
<?
}
}
?>
</center>
</body>
</html>
答案 0 :(得分:1)
您有两个不同的表单标记,而不是一个包含所有字段的表单。
答案 1 :(得分:0)
您正在使用两种不同的形式,并引用不同的表单元素。像这样编辑使用单一形式。并使用method="post"
代替method=post
<form method="post" action= "">
Name: <input type="text" name="username">
I am:
<input type="radio" name = "gender" value = "male"> Male
<input type="radio" name = "gender" value = "female"> Female
Ethnicity:
<input type="radio" name = "race" value = "asian">Asian
<br>
<br>
<input type="radio" name = "race" value = "black">Black
<br>
<br>
<input type="radio" name = "race" value = "white">White
<br>
<br>
<br>
<input type="submit" name="Button" value = "Who will I marry?">
</form>