php添加数据为什么只能填加数字和英文,添加文字就会报错

WBOY
Release: 2016-06-23 14:17:51
Original
1204 people have browsed it

PHP MySQL

用php写了一段代码,添加数据只能填加数字和英文,添加文字就会报错,求位高手帮我解决下着个问题。
下面是报错:
执行错误Incorrect string value: '\xE8\xB4\xB9\xE6\x98\xAF...' for column 'n_content' at row 1
以下是代码:
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('执行错误'.mysql_error())  ;

    if($rat){
     echo '插入成功';
    }else{
        echo '插入失败';
    }
    mysql_close($con );
}
mysql_close($con);
?>

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">





Auto Height Examples

<script></script>
<script></script>
<script> <br /> KindEditor.ready(function(K) { <br /> K.create('textarea[name="content"]', { <br /> autoHeightMode : true, <br /> afterCreate : function() { <br /> this.loadPlugin('autoheight'); <br /> } <br /> }); <br /> });//手动调节高度 <br /> </script>
<script></script>
        <script> <br /> KE.init({ <br /> id : 'editor_id' <br /> }); <br /> $.ready(function() { <br /> KE.create('editor_id'); <br /> }); <br /> KE.show({ <br /> id : 'editor_id' <br /> }); <br /> </script>



    标题: 

内容:




回复讨论(解决方案)

你数据库内定的编码是ASCII?

终于找到问题出在哪了
更改mysql中的配置 my.ini my.ini中查找sql-mode, 默认为sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION", 将其修改为sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION",重启mysql后即可

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!