MySQL Insert Special Characters

I had a registration form that will be inserted into the member table, sorting is in utf8_general_ci , and I use SET NAMES utf8 in a PHP script, here is the problem, I can’t insert a line other than the pure alphabet, I try to enter “Hélène” in the field forms, after executing the sql query, I check my db table, the field is inserted as "H", the rest of the alphabet cannot be inserted whenever a line comes with a special alphabet, for example é, ř behind.

Can anybody help? thanks.

DECISION:

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> mysql_query("SET NAMES utf8"); 

The above two lines is an important part for accepting database input and output on a web page.

Thanks to everyone for the advice.

+6
source share
3 answers

try pasting the data after encoding. try mysql_real_escape_string() for coding. then execute the insert request.

EDIT: -

This answer was posted a year ago. Now mysql_real_escape_string () for php 5 will work in mysqli :: real_escape_string in this format. please check here

+2
source

Make sure you create your database using utf8 encoding

 CREATE SCHEMA `youdatabasename` DEFAULT CHARACTER SET utf8; 
+1
source

And if you don’t want to worry about so many different encodings or if htmlentities doesn’t work for you, here is an alternative: I used the mysqli DB connection (and PHPV5) form message for writing / pasting to MySQl DB.

 $Notes = $_POST['Notes']; //can be text input or textarea. $charset = mysqli_character_set_name($link); //only works for mysqli DB connection printf ("To check your character set but not necessary %s\n",$charset); $Notes = str_replace('"', '&quot;', $Notes); //double quotes for mailto: emails. $von = array("ä","ö","ü","ß","Ä","Ö","Ü"," ","é"); //to correct double whitepaces as well $zu = array("&auml;","&ouml;","&uuml;","&szlig;","&Auml;","&Ouml;","&Uuml;","&nbsp;","&#233;"); $Notes = str_replace($von, $zu, $Notes); echo " Notes:".$Notes."<br>" ; $Notes = mysqli_real_escape_string($link, $Notes); //for recommended mysqli DB connection. //$Notes = mysql_real_escape_string($Notes); //for old deprecated mysql DB connection. // mysqli_real_escape_string Escapes special characters in a string for use in an SQL statement echo " Notes:".$Notes ; //ready for inserting 
+1
source

All Articles