Jump to content

Problem using mysql_real_escape_string


forumnz

Recommended Posts

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?

Link to comment
Share on other sites

Hold on a minute. Look at your query.

SELECT * FROM articles WHERE keywords LIKE '%$q%'

That query says "SELECT all fields FROM table WHERE keywords [contains the value in $q anywhere, regardless of its position in the string]"

 

Is that what you mean for it to say?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.