I am pretty new to jQuery, so I need some help here:
I just started using jQuery Autosuggest Plugin, because I would really help my site. I downloaded all of the files, linked them to my site, and used this, to set an input as autosuggest:
<script>
$(document).ready(function(){
$("#postna").autoSuggest("get.php");
})
</script>
Now this part works fine, it changes the style of my input box. And for get.php file, I pretty much copied it from the plugin site, but I changed it, so it would serve me better:
<?php
require_once 'includes/mysql.class.php';
$input = $_GET['q'];
$data = array();
$qu = new MySQL();
$qu->rQuery("SELECT id,name FROM cities WHERE name LIKE '$input%'");
$data = $qu->getRows();
foreach($data as $a){
$json = array();
$json['value'] = $a['id'];
$json['name'] = $a['name'];
$data[] = $json;
}
header("Content-type: application/json");
echo json_encode($data);
?>
The problem now is, that when I input my text it returns “No results found”, but if I go to /get.php?q=velenje (velenje is a name of a city), it echoes this:
{"id":"681","name":"Velenje"}
Any suggestion on what I might be doing wrong?
You’re pulling the results of your MySQL query into an array
$dataand then proceeding to edit that array in a loop. Try this:EDIT: I forgot to note that you don’t appear to be sanitizing your inputs… Little Bobby Tables shows us why we shouldn’t do that.