Data pulled from SQL showing up with \ before quotations.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
davidshq
Forum Newbie
Posts: 12
Joined: Mon May 05, 2008 10:47 pm
Location: Pennsylvania

Data pulled from SQL showing up with \ before quotations.

Post by davidshq »

So, I have this nifty new in-line AJAX/PHP editor which allows me to edit "stories" on my site without moving between multiple pages. Everything works great - except for one small detail. If the story contains quotations (e.g. " or ') the text appears as \'. For example, "The problem with web crime is \"who cares?\" It doesn\'t matter if we\'re talking about identity theft or credit card fraud, if it\'s done to you,". Any thoughts?
David.
whiterabbit
Forum Newbie
Posts: 14
Joined: Thu May 22, 2008 6:58 pm

Re: Data pulled from SQL showing up with \ before quotations.

Post by whiterabbit »

That is probably because gpc magic quotes is on. This is a setting that automatically escapes (adds in the \ before certain characters) strings before they are entered into your database. Before you enter the data into the database, you probably want to do a stripslashes() on the data, or you could do it on the display side.

You could also turn off gpc magic quotes in your php.ini file. You should always make sure you do a mysql_real_escape_string($string) when you are entering anything into the database to make sure you protect against SQL injection.

Hope this helps.
Post Reply