Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I installed xampp on localhost and insert data contain quote using this php code

$content    = htmlentities($_POST['content']);
$content_esc = mysql_real_escape_string($content);
$save = mysql_query("INSERT INTO tbl_post (title,content,date,publish) values('$title_esc','$content_esc','$date','$publish')");

The result on localhost website is

this is 'example data'

The row on database filled with this

this is "example data"

But using the same code to insert data the result from my hosting provider is different

this is \'example data\'

The row on database filled with this

this is \"example data\"

I test my website on localhost, insert post contain quote and it show on page correctly. Then i surprise when i upload on online hosting, insert post and the post page show '\' before the quote.

At this time i replace the '\' with nothing. How to insert the quote so it can show same result on local mysql database and online mysql database ? What is wrong, my php code or my mysql database ?

share|improve this question
can you post the output of this query SHOW VARIABLES LIKE '%character_set%'; from localhost and online server – altmannmarcelo May 3 '13 at 18:26
here the output – Yusufmm May 3 '13 at 18:44
Provide the result from this query from both servers SELECT character_set_name FROM information_schema.COLUMNS WHERE table_schema = "DATABASE" AND table_name = "tbl_post" AND column_name = "content"; Change table_schema = "DATABASE" to your database name – altmannmarcelo May 3 '13 at 19:37
Please also run SHOW CREATE DATABASE dbname; for every database on the Local Server and the Remote Server. – RolandoMySQLDBA May 3 '13 at 20:35

Looks PHP issue, I bet you have Magic Quotes turned off on local (good!) whereas your hosting privider has turned them on - When they're turned on it's the same like if you'd write:

$content    = htmlentities(addslashes($_POST['content']) );//HERE: addslashes is basically the same like your mysql_real_escape_string() - this means contents of $_POST get escaped automatically
$content_esc = mysql_real_escape_string($content);
$save = mysql_query("INSERT INTO tbl_post (title,content,date,publish) values('$title_esc','$content_esc','$date','$publish')");

I also guess that next time you're better asking such a question on StackOverflow instead;)

share|improve this answer
thanks so much, it work ! – Yusufmm May 4 '13 at 2:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.