简体   繁体   English

如何知道 $_POST 是否有效 php

[英]How to know if $_POST works php

I have this code:我有这个代码:

if (isset($_POST['food-input']) && $_POST['food-input']!="") {
    echo "RABOTI !!";
}                         

'food-input' is the name of my Input box with type="text" it, but it doesn't print given echo, what can i do to make it work. 'food-input' 是我的输入框的名称, type="text"它,但它不会打印给定的回声,我该怎么做才能让它工作。 And other question will code work with !="" at the end,i wanna tell to server if'food-input' have something in it and IS NOT EMPTY(second $_POST method) to post the given information.其他问题将在最后使用!=""进行编码,我想告诉服务器“食物输入”中是否有内容并且不是空的(第二个 $_POST 方法)来发布给定的信息。 Thanks!!谢谢!!

EDIT: There is the HTML .编辑:有 HTML 。

 <!---------------------------------------------------------------- HTML -----------------------------------------------------------------> <p>Търсене на храни: <input type="text" name="food-input" id="food_search"></p> <div id="food_search_result"></div>

step by step一步步

try to activate error messages尝试激活错误消息

How do I get PHP errors to display? 如何显示 PHP 错误?

and after之后

 var_dump($_POST['food-input']);

Based on the HTML you provided, if that's the full code - you're missing the most important tag - the actual <form> tag.根据您提供的 HTML,如果这是完整的代码 - 您缺少最重要的标签 - 实际的<form>标签。 Simply put it inside a form, using the POST method.只需使用 POST 方法将其放入表单中即可。 After submitting it, you can then use the information submitted in the $_POST array.提交后,就可以使用$_POST数组中提交的信息了。

<form method="POST">
    <p>Търсене на храни: <input type="text" name="food-input" id="food_search"></p>
</form>
<div id="food_search_result"></div>

Also, instead of doing此外,而不是做

if (isset($_POST['food-input']) && $_POST['food-input']!="") {

you can replace that entire line by the below, which does exactly the same你可以用下面的替换整行,它的作用完全相同

if (!empty($_POST['food-input'])) {

Reference参考

You can do,你可以做,

$test = $_POST['name_of_form'];
echo $test;
die ();

Regards问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM