Jump to content

Annoying \'s


Ashbow97

Recommended Posts

I'm not 100% sure if this is to do with PHP or MySQL mainly, but probably it includes both :)

 

I'm trying to create a kind of guestbook/comment system on my website which is working pretty well so far, but I'm having one problem with \ when I'm inserting data into the MySQL database. Everytime I insert a word such as don't... it would come up in the database as don\'t. Then it also appears on the page that I've selected it for with don\'t which isn't very good. I know it's more than likely to make it so you can't break the code or something, but is there any way that when I select the data from the database, that it automatically gets rid of all the \s or something like that.

 

Thanks, Ashbow97 :)

Link to comment
https://forums.phpfreaks.com/topic/238462-annoying-s/
Share on other sites

If you're getting slashes actually inserted in the database, you aren't handling the data properly before inserting it. It's probably because magic_quotes_gpc is on, and you haven't checked for it before using mysql_real_escape_string().

 

if( get_magic_quotes_gpc() ) {
     $data = stripslashes($data);
     $data = mysql_real_eascape_string($data);
} else {
     $data = mysql_real_eascape_string($data);
}

Link to comment
https://forums.phpfreaks.com/topic/238462-annoying-s/#findComment-1225443
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.