I have an AJAX script which queries a DB when a user inputs a search text. That's great, works well.
However, when I use mysql_real_escape_string, it seems to completely rid the '$q'. When I don't use it, it works well but of course, there's the security side of things.
Here's the code snippet:
<?php
error_reporting(E_ALL);
$q = $_GET["q"];//added mysql_real_escape_string
//$q = mysql_real_escape_string('$_GET["q"]');
$con = mysql_connect("localhost","aaaaa","aaaaa");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("aaaaa", $con);
$sql="SELECT * FROM articles WHERE keywords LIKE '%$q%'";
?>
It seems so simple, but its just not working. What could it be?