I am trying to use a code that was flagged as working and I am not getting any results, it's just empty. Notes: The MySQL does return results if run alone, so it's not an sql thing. Any suggestions?
HTML:
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
Name: <input id="hint" />
<script type="text/javascript">
$("#hint").autocomplete({
source: function (request, response) {
$.ajax({
url: "getMedicineNames.php",
dataType: "jsonp",
data: {
name: request
},
success: function (data) {
response(data);
}
});
},
minLength: 3
});
</script>
</body>
PHP:
require 'connect.inc.php';
$mysql = mysqli_connect("$db_host", "$db_username", "$db_pass", "$db_name");
$name = $_POST['name'];
if ($name != "") {
$sql = "SELECT MedicineName FROM medicinetypes WHERE MedicineNAme LIKE '%$name%'";
echo json_encode(mysqli_fetch_all(mysqli_query($mysql, $sql), MYSQLI_ASSOC));
}