1

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. 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. Thanks!!

EDIT: There is the HTML .

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

3 Answers3

1

step by step

try to activate error messages

How do I get PHP errors to display?

and after

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

Based on the HTML you provided, if that's the full code - you're missing the most important tag - the actual <form> tag. Simply put it inside a form, using the POST method. After submitting it, you can then use the information submitted in the $_POST array.

<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

Qirel
  • 25,449
  • 7
  • 45
  • 62
  • I am really thankfull to guys like you with exhaustive answers,THANKS mate.I already fixed my problem and marked this question for solved,i voted for you if there is anything other i can do(because i am new in this site) feel free to say me <3 Thanks one more time – Tsvetomirov Yordan Jan 13 '17 at 20:03
-1

You can do,

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

Regards

juanitourquiza
  • 2,097
  • 1
  • 30
  • 52