php + mysql插入错误 [英] php + mysql insert error

查看:141
本文介绍了php + mysql插入错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个简单的表单注释,允许用户发送评论和插入到数据库使用php mysql jquery在页面中没有刷新所有工作正常,但问题是:
,当我写我注释mysql数据库采取4行,并填写相同的数据在任何人都可以帮助我的错误??
$ b

my_db.sql



   -  
- 数据库:`my_db`
-

- ------- -------------------------------------------------

-
- 表'comment`的表结构
-

CREATE TABLE IF NOT EXISTS`comments`(
` id` tinyint(4)NOT NULL AUTO_INCREMENT,
`name` varchar(50)NOT NULL,
`email` varchar(70)NOT NULL,
`comment` text NOT NULL,
PRIMARY KEY(`id`)
)ENGINE = InnoDB DEFAULT CHARSET = latin1 AUTO_INCREMENT = 5;

-
- 表格`评论'的转储数据
-

插入`comments`(`id`,`name` ,'email`,`comments`)值
(1,'test','test@test.com','testcomments'),
(2,'test','test @ test。 ('test','testcomments'),
(3,'test','test@test.com','testcomments'),
(4,'test','test@test.com' ,'testcomments');

/ *!40101 SET CHARACTER_SET_CLIENT = @ OLD_CHARACTER_SET_CLIENT * /;
/ *!40101 SET CHARACTER_SET_RESULTS = @ OLD_CHARACTER_SET_RESULTS * /;
/ *!40101 SET COLLATION_CONNECTION = @ OLD_COLLATION_CONNECTION * /;



index.php //其中jquery的形式和函数



 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/ XHTML1 / DTD / XHTML1-transitional.dtd> 
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title>反馈页面< / title>
< script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js\">< ;; script>
< link rel =stylesheethref =css / default.css/>

< script type =text / javascript>
$ b $(function(){

$('#submit')。click(function(){
$('#container')。append( '< img src =img / loading.gifalt =目前正在加载id =loading/>');

var name = $('#name')。val ();
var email = $('#email')。val();
var comment = $('#comments')。val();


$ .ajax({

url:'submit_to_db.php',
type:'POST',
data:'name ='+ name +'& email ='+ email +'& comment ='+评论,

成功:功能(结果){
$('#response')。remove();
$('#container')。append('< p id =response>'+ result +'< / p>');
$('#loading')。fadeOut(500,函数(){
$(this).remove();
});

}

});

返回false;

});


});

< / script>




< / head>

< body>
< form action =submit_to_db.phpmethod =post>
< div id =container>
< label for =name>名称< / label>
< input type =textname =nameid =name/>

< label for =email>电子邮件地址< / label>
< input type =textname =emailid =email/>

< label for =评论>评论< / label>