Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to prevent database to add slash to quotes

i know this sounds really common and so trivial but , am having a challenge here. I have a web site with Zend/Doctrine and i use ckeditor for the backend management. after uploading the site i've realized that during edit testing the look and feel of the site is messed up.

with the help of firebug, i've seen that there are slashes all over the html. after inline edition, the look and feel came back to normal. There are so many files , i can't think of doing other decoding before outputting data from mysql.

What options do i have to solve this problem. the site is up already and i feel a bit unconfortable about this. Can anyone give a hint? thanks

like image 376
black sensei Avatar asked Jun 20 '12 01:06

black sensei


People also ask

Why Backticks in SQL?

Backticks are used in MySQL to select columns and tables from your MySQL source. In the example below we are calling to the table titled Album and the column Title . Using backticks we are signifying that those are the column and table names. SELECT `Album`.

How to escape single and double quotes in MySQL?

Similarly, we can use backslash to escape single quotes and double quotes to insert values into MySQL table.

How to use Backticks in SQL?

Backticks ( ` ) are used to indicate database, table, and column names. Unless you're using reserved or conflicting words for table and database names, you'll not need to use them. Quotes ( ' or " ) are used to delimit strings, and differentiate them from column names.


2 Answers

It might be magic_quotes_gpc. Can you verify that it's turned off?

Here is a way to turn it off: http://php.net/manual/en/security.magicquotes.disabling.php

Sets the magic_quotes state for GPC (Get/Post/Cookie) operations. When magic_quotes are on, all ' (single-quote), " (double quote), \ (backslash) and NUL's are escaped with a backslash automatically.

Also, are you using prepared statements? PHP PDO/MySQLI will escape automatically for you. Depends on the type of queries you're using.

like image 74
stan Avatar answered Oct 07 '22 20:10

stan


It seems like you're data is getting double escaped before being inserted into your database. Are you using mysql_real_escape_string or addslashes before inserting data into the database? If so, maybe you want to use stripslashes before you insert your data like so:

mysql_real_escape_string(stripslashes($data));

Or else you could theoretically call stripslashes after you take the data out of the database:

stripslashes($data);

The second approach is less desirable, though. It would be better to have the data properly stored in the database.

like image 29
Michael Frederick Avatar answered Oct 07 '22 21:10

Michael Frederick