我想做一些错误检查。我想这样做,如果在html页面上没有选中单选按钮,它将传递给php并告诉用户选择单选按钮和链接返回到该页面。在PHP中切换语句
包括的是我当前的代码:
PHP
<?php
switch($_POST["city"]){
case "sf":
echo "Welcome to San Francisco, enjoy the beautiful weather.";
break;
case "tokyo":
echo "Welcome to Tokyo, enjoy the sushi.";
break;
case "paris";
echo "Welcome to Paris, enjoy the Eiffel Tower.";
break;
Default:
echo "Please pick a city.";
echo "<a href=\"/week7.html\">Go Back</a>";
}
?>
HTML
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>
<form action="Week7PHP.php" method="post">
<input type="radio" name="city" value="sf">San Francisco<br />
<input type="radio" name="city" value="paris">Paris<br/>
<input type="radio" name="city" value="tokyo">Tokyo<br/>
<input type="submit" id="Submit">
</form>
</div>
</body>
</html>
这是给当它没有发现任何检查单选按钮的错误。
这是如果没有选项选择了错误:注意:未定义指数:城市
什么 “错误” 它给? – penartur 2012-02-20 05:29:12
在切换前echo $ _POST [“city”]。检查它给出了什么。 – 2012-02-20 05:30:04
注意:未定义索引:city 多数民众赞成除了在“巴黎”语法明智之后的分号错误 – stytown 2012-02-20 05:33:11