我已经制作了两个文件 php,一个有验证 php 代码,另一个有我输入一些数据的表单,但看起来 Switch 命令有问题,看了很多次才发现问题,但不幸的是我没有得到 true .这是我的代码;我已经形成的第一个文件<form action="Validation_search_02.php" method="post"><label>Your favourite fruit:<input type="text" name="t_Opst" id="t_Opst"></label><input type="submit" name="G_mby" id="G_mby"></form>我有验证文件的第二个文件(php)<?phpif(isset($_P0ST["G_mby"])){$L_ings=$_POST["t_Opst"];switch($L_ings){case "Apple": echo "Your favourite fruit is $L_ings";break;case "Pear":echo "Your favourite fruit is $L_ings";break;case "Banana": echo "Your favourite fruit is $L_ings";break;case "Mango": echo "Your favourite fruit is $L_ings";break;default:echo "You should eat some fruit";}}?>
1 回答
宝慕林4294392
TA贡献2021条经验 获得超8个赞
在您的 php 文件中,您可以验证是否有 POST 请求,当涉及到您的代码时,不需要切换,因为相同的代码会重复多次,您可以使用 if 和 or 子句代替。尝试这个:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$L_ings = $_POST["t_Opst"];
echo "hola";
if($L_ings == "Pear" or $L_ings == "Banana" or $L_ings == "Mango" or $L_ings == "Apple")
echo "Your favourite fruit is $L_ings";
else
echo "You should eat some fruit";
}
?>
- 1 回答
- 0 关注
- 65 浏览
添加回答
举报
0/150
提交
取消