0

为什么这不起作用或者我只是愚蠢?它不打印任何东西,单击按钮后页面看起来完全一样(我的<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 &nbsp; &nbsp;

<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>
4

2 回答 2

1

您有两个不同的表单标签,而不是一个包含所有字段的表单。

于 2012-11-28T05:30:32.667 回答
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 &nbsp; &nbsp;

<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>
于 2012-11-28T05:30:08.870 回答