addslashes vs. mysql_real_escape_string

This is a discussion on addslashes vs. mysql_real_escape_string within the PHP Language forums, part of the PHP Programming Forums category; When I look directly in my db field I see a difference between these two functions. The top line (seebelow) ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-10-2004
leegold2
 
Posts: n/a
Default addslashes vs. mysql_real_escape_string


When I look directly in my db field I see a difference between these two
functions. The top line (seebelow) was inserted with addslashes vs. the
bottom line where I used mysql_real_escape_string. Obviously addslashes
really escapes the apostrophe. But I thought mysql_real_escape_string is
supposed to do that too - can anyone explain? Thanks, Lee G.

This is Aviva\'s website.
This is Sarah's website.
Reply With Quote
  #2 (permalink)  
Old 10-10-2004
Brion Vibber
 
Posts: n/a
Default Re: addslashes vs. mysql_real_escape_string

leegold2 wrote:
> When I look directly in my db field I see a difference between these two
> functions. The top line (seebelow) was inserted with addslashes vs. the
> bottom line where I used mysql_real_escape_string. Obviously addslashes
> really escapes the apostrophe. But I thought mysql_real_escape_string is
> supposed to do that too - can anyone explain? Thanks, Lee G.
>
> This is Aviva\'s website.
> This is Sarah's website.


What were:
* the original strings before escaping
* the strings after escaping, as they appeared in the SQL you sent to
the server?

I don't see any difference on a test string with an apostrophe on these
functions in 4.3.8 or 5.0.2:
<?php
$originalstring = "Apostrophe's rock";
echo $originalstring, "\n";
echo addslashes( $originalstring ), "\n";
echo mysql_escape_string( $originalstring ), "\n";
echo mysql_real_escape_string( $originalstring ), "\n";
?>

output:
Apostrophe's rock
Apostrophe\'s rock
Apostrophe\'s rock
Apostrophe\'s rock

Can you confirm that the pre-escaping string for "This is Aviva\'s
website." did not contain a backslash, and that the same query was used
to insert both samples? Did the data from from a literal string, a file,
or from a web form? If you're using the magic_quotes_gpc option
(unfortunately the default is on, I believe), you need to run
stripslashes() on any text that comes from GET/POST/COOKIE variables
before further processing.

-- brion vibber (brion @ pobox.com)
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:41 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0