php - 验证文件找不到表单数据
问题描述
我已经制作了两个文件 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";
}
}
?>
解决方案
在您的 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";
}
?>
推荐阅读
- python - Django 按名称查询 content_type 而不是 content_type_id
- r - 如何取消列出字符串列以计算匹配项?
- json - 在 Dart/Flutter 中解析嵌套的 JSON
- python - 微调超参数不会提高分类器的分数
- angular - 角 9 SSR | 无法访问 ads.txt 文件
- postgresql - 如何在 PostgreSQL 中通过 cmd 使用 pg_restore 命令恢复 .bak 文件?
- unity3d - 为子像素阴影映射编码几何信息
- python - 如何处理 Python Selenium 中的“消息:过时的元素引用:元素未附加到页面文档”
- javascript - Javascript - 为存储在用户计算机上的静态网页读取/写入设置的推荐/安全方式是什么?
- html - 为什么叠加的图片和标志+文字不起作用?