Hello I am a beginner in php and jQuery so an early sorry if my question is stupid. I have been searching quite a lot on ajax live search but there is not much help on internet... So when I type something in my input box nothing comes out, so I thought it was a problem to connect to the database but that works fine. And now I don't really know what to do because my code sounds right (even though it's not :-) ). If someone could help me it would be great thank you.
Here are the codes: HTML:
<!DOCTYPE html>
<html>
<head>
<title>live search test</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script scr="jquery.js"></script>
<script type="text/javascript">
functon getNames(value) {
$.post("fetch.php",{partialName:value},function(data)
$("#results").html(data);
});
}
</script>
</head>
<body>
<h1>LIVE SEARCH WITH AJAX TEST</h1>
<input type="text" onkeyup="getNames(this.value)">
<br>
<div id="results">
</div>
</body>
</html>
PHP:
<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("smartphone")or die(mysql_error());
$partialName = $_POST['partialName'];
$names = mysql_query("SELECT name FROM smartphone WHERE name LIKE '%$partialName%'");
while ($name = mysql_fetch_array($names)) {
echo"<div>".$name['name']."</div>";
}
?>