How to use PHP if conditions to act according to the input of a search bar in HTML -


so i've got code search bar in html specific fruit names passed onto php page, echoes message in reply...

here's html code -

    <form action="pass.php" method="post">  <input type="text" id="find" name="search"/> <button  type="submit"  onclick="javascript: if(document.getelementbyid('find').value!='banana' && document.getelementbyid('find').value!='apple')  {alert('fruit not found');return false;}">&nbsp</button> </div> </div> </div> </form> 

and here php code...

if ($_post['id'] = "banana") {     echo "this banana"; }      else {     echo "this not banana"   } 

the output gives me "this banana" regardless of input. know code wrong, can't seem figure out how fix it.

your $_post variable has wrong key value, should be:

  if ($_post['search'] == "banana") {     echo "this banana";   }else {     echo "this not banana"     } 

and comparison operator wrong according @lluisrojass.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -