Reputation: 77
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>
Upvotes: 1
Views: 62
Reputation: 26490
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'])) {
Upvotes: 1
Reputation: 2194
You can do,
$test = $_POST['name_of_form'];
echo $test;
die ();
Regards
Upvotes: -1
Reputation:
step by step
try to activate error messages
How do I get PHP errors to display?
and after
var_dump($_POST['food-input']);
Upvotes: 1