MySQLi插入准备错误 [英] MySQLi insert into prepare error
本文介绍了MySQLi插入准备错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在mysql数据库中插入了很多东西.
Hi I inserted a lot of stuff into a mysql databse.
但是现在我在prepare语句中遇到错误.我看到数据库准备错误.我在做什么错了?
But now I get an error in the prepare statement. I see Database prepare error. What am I doing wrong?
这是我的代码:
$sql = "INSERT INTO
Contact (IP,To,Name,Email,Subject,Text)
VALUES
( ?, ?, ?, ?, ?, ? )
";
if (!$stmt = $db->prepare($sql)) {
echo 'Database prepare error';
exit;
}
$stmt->bind_param('ssssss', $ip_contact, $to_contact, $name_contact, $email_contact, $subject_contact, $text_contact);
if (!$stmt->execute()) {
echo 'Database execute error';
exit;
}
$stmt->close();
我的SQL表如下:
Contact:
- ID int(11) auto_increment primary key
- IP varchar(15)
- To varchar(5)
- Name varchar(20)
- Email varchar(20)
- Subject varchar(20)
- Text varchar(600)
推荐答案
For example to
is a reserved word in mysql, you should change your code to:
$sql = "INSERT INTO
`Contact` (`IP`,`To`,`Name`,`Email`,`Subject`,`Text`)
VALUES
( ?, ?, ?, ?, ?, ? )
";
这篇关于MySQLi插入准备错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文