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 ?
SHOW VARIABLES LIKE '%character_set%';
from localhost and online serverSELECT character_set_name FROM information_schema.COLUMNS WHERE table_schema = "DATABASE" AND table_name = "tbl_post" AND column_name = "content";
Changetable_schema = "DATABASE"
to your database nameSHOW CREATE DATABASE dbname;
for every database on the Local Server and the Remote Server.