I'm doing a search page that takes information from a database. I want a search that is something like the one from http://designspiration.net/ website.
So what I want is that it shows results without pressing enter or submit so it shows suggestions according to the letters written.
I have something like this so far:
div class="container">
<div class="row">
<div class="col-md-10">
<form action="#" method="POST">
<textarea name="search"></textarea>
<input type="submit" name="enter_search" >
</form>
</div>
</div>
<?php
if (isset($_POST['enter_search'])) {
$name = $_POST['search'];
$sql = <<<SQL
SELECT `name`
FROM `teachers`
WHERE `name` LIKE '%{$name}%'
SQL;
if(!$result = $con->query($sql)){
die('There was an error running the query [' . $con->error . ']');
}
while($row = $result->fetch_array()){
echo $row['name'] . '<br />'; }
}
?>
</div>
If I add a submit button it works, but I can't make it work without it. Thank you for your help :)