Can anyone tell me how to insert special characters into a MySQL database? I've made a PHP script which is meant to insert some words into a database, although if the word contains a ' then it wont be inserted.
I can insert the special characters fine when using PHPmyAdmin, but it just doesn't work when inserting them via PHP. Could it be that PHP is changing the special characters into something else? If so, is there a way to make them insert properly?
You are propably pasting them directly into a query. Istead you should "escape" them, using appriopriate function - mysql_real_escape_string, mysqli_real_escape_string or PDO::quote depending on extension you are using.
Assuming that you have the data stored as
$input_data
Probably "
mysql_real_escape_string()
" will work for uFor Example:
$parent_category_name = Men's Clothing
Consider here the SQL query
Error:
Try to implement:
The above method works on OpenCart framework. Find your framework & implement OR
mysql_real_escape_string()
in Core PHPThis will become Men\'s Clothing i.e, In my case
So you'll get the clear picture of the query by implementing escape() as
htmlspecialchars function is the best solution fellows. Today I was searching for how to insert strings with special characters and the google thrown so many Stackoverflow listings.None of them provided me solution. I found it in w3schools page. Yes I could solve my problem by using this function like this: