验证文件找不到表单数据

我已经制作了两个文件 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)


<?php


if(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";


}

}

?>


红糖糍粑
浏览 66回答 1
1回答

宝慕林4294392

在您的 php 文件中,您可以验证是否有 POST 请求,当涉及到您的代码时,不需要切换,因为相同的代码会重复多次,您可以使用 if 和 or 子句代替。尝试这个:<?php&nbsp; if ($_SERVER["REQUEST_METHOD"] == "POST"){&nbsp; &nbsp; $L_ings = $_POST["t_Opst"];&nbsp; &nbsp; echo "hola";&nbsp; &nbsp; if($L_ings == "Pear" or $L_ings == "Banana" or $L_ings == "Mango" or $L_ings == "Apple")&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo "Your favourite fruit is $L_ings";&nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo "You should eat some fruit";&nbsp; }?>
打开App,查看更多内容
随时随地看视频慕课网APP