Hey all, I made a textbox which autocompletes input by getting stuff from a database and it works like this now:
<script type="text/javascript">
$().ready(function() {
$("#food").autocomplete("get_course_list.php", {
width: 260,
cacheLength: 10,
matchContains: false,
//mustMatch: true,
//minChars: 0,
//multiple: true,
//highlight: false,
//multipleSeparator: ",",
selectFirst: true
});
});
</script>
and this in the .php file:
<?php
require_once "config2.php";
$q = strtolower($_GET["q"]);
if (!$q) return;
$sql = "select DISTINCT voedsel as voed from voedingswaarden where voedsel LIKE '%$q%'";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
$cname = $rs['voed'];
echo "$cname\n";
}
?>
But now i read about sql injections etc so I wanted to protect my php script against that with mysql_real_escape_string(); but I can't seem to get it to work. Any ideas how to implement this in my .php file and if this is enough protection?
but I can't seem to get it to work.- how did you try?