2 回答
TA贡献2065条经验 获得超13个赞
您需要将条件格式从更改if($isMale =="y" || "yes"){为if($isMale =="y" || $isMale =="yes"){
<HTML>
<body>
<?php
echo "<H4>Are you a Male</h4>"
?>
<form action ="ifstat.php" method ="post">
Enter Please: <input type="text" name="val1">
<input type ="submit" >
<input type ="reset">
</form>
<?php
$isMale=$_POST["val1"];
if($isMale =="y" || $isMale =="yes"){
echo("You are a Male");
} elseif($isMale =="n" || $isMale =="no") {
echo("You are a female");
} else{
echo("Invalid entry");
}
?>
</body>
</html>
TA贡献1824条经验 获得超8个赞
在你的if陈述中......
if($isMale =="y" || "yes" ){
the|| "yes"无效,并且总是(在这种情况下)评估为真。
您也不会在处理之前检查是否输入了任何内容,因此通常您会检查是否设置了某些内容(即是否已提交表单)然后进行处理...
<?php
if (isset($_POST["val1"])) {
$isMale=$_POST["val1"];
if($isMale =="y" || $isMale =="yes"){
echo("You are a Male");
} elseif($isMale =="n" || $isMale =="no") {
echo("You are a female");
} else {
echo("Invalid entry");
}
}
?>
- 2 回答
- 0 关注
- 85 浏览
添加回答
举报