PHP MySQL
Write a piece of code in PHP, add data can only fill in numbers and English, add text will be error, ask a master to help me solve the next problem.
The following is an error:
Execution error Incorrect string value: ' \xe8\xb4\xb9\xe6\x98\xaf ' for column ' N_content ' at row 1
Here's the code:
Header ("Content-type:text/html;charset=utf-8");
if ($_post[' Submit ']!= "") {
$i =$_post[' id '];
$t =$_post[' title ';
$c =$_post[' content ';
$con =mysql_connect ("localhost", "root", "root");
mysql_select_db ("Test", $con);
$sql = "INSERT into News (n_id,n_title,n_content) VALUES (NULL, ' $t ', ' $c ');";
Echo $sql;
$rat =mysql_query ($sql, $con) or Die (' execution error '. Mysql_error ());
if ($rat) {
echo ' Insert success ';
}else{
Echo ' Insert failed ';
}
Mysql_close ($con);
}
Mysql_close ($con);
?>
<title></title>
<title>Auto Height Examples</title>
Reply to discussion (solution)
Your database default encoding is ASCII?
Finally find out where the problem is.
Change the configuration in MySQL My.ini my.ini find Sql-mode, default to Sql-mode= "Strict_trans_tables,no_auto_create_user,no_engine_substitution ", modify it to sql-mode=" no_auto_create_user,no_engine_substitution "and restart MySQL