Jump to content

mysql_real_escape_string doesn't do anything?


LLLLLLL

Recommended Posts

Never had this one before.

 

Here's a string from a URL:

$urltext = Product_Name_'with_single_quotes'_"_B

$name = str_replace( "_", " ", $urltext );
echo 'raw: ' . $name . "<br>";
$name = mysql_real_escape_string( $name );
echo 'mysql_real_escaped: ' . $name . '<br>';

 

Doesn't seem possible, but both of the "echos" return the same string. My query fails because there are no backslashes in the SQL statement. What's going on here?

 

raw: Product Name 'with single quotes' " B

mysql_real_escaped: Product Name 'with single quotes' " B

Link to comment
Share on other sites

The source of the page shows:

 

raw: Product Name &#039;with single quotes&#039; " B<br>mysql_real_escaped: Product Name &#039;with single quotes&#039; " B

 

The only problem is that there are not backslashes in this string; I get the normal mysql error. I'm really just concerned with why I'm not getting the backslashes to escape the string.

Link to comment
Share on other sites

I realize the source shows those are entities, but that's not what the GET array is giving me.

 

Standard unescaped query:

SELECT * FROM products WHERE name = 'Product Name 'with single quotes' " B'

 

Standard error

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'with single quotes' " B' LIMIT 0, 30' at line 1

 

Link to comment
Share on other sites

I realize the source shows those are entities, but that's not what the GET array is giving me.

 

What source? What get array? To get the quickest solution to what your code is doing, post all the code needed to reproduce the problem. For all we know you aren't even using the variables you have shown in the actual query statement.

Link to comment
Share on other sites

We only see the information you supply in your posts. The code you did post and the 'view source' of the echoed output from that code (you did post the view source output from those 4 lines of code?) could not have produced the query error you stated you were getting. Therefore, something in the rest of your code was not putting that data into your query, but was putting data that had actual quotes, un-escaped ones, into the query.

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.