感谢raina77ow解决了这个问题。 来自和来的人正在弄乱准备好的陈述。
在过去的6个小时里,我已经查看了这个内容,但是我无法让这个参数化语句起作用。但是,我有其他参数化的语句,看起来完全像这样。我知道我准备好的陈述有问题,但我似乎无法找到错误。有一双新鲜眼睛的人可以帮助我吗?
function insert_event($post_id, $title, $location, $from, $to, $description)
{
//open connection to database
$mysqli = db_connect();
//insert
$stmt = $mysqli->prepare("INSERT INTO Events (".
"postID, ".
"title, ".
"location, ".
"from, ".
"to, ".
"description) ".
"VALUES (".
"'$post_id', ".
"?, ".
"?, ".
"?, ".
"?, ".
"?)");
$stmt->bind_param("sssss", $title, $location, $from, $to, $description);
$stmt->execute();
$stmt->close();
// close connection
$mysqli->close();
}
我甚至试过这个
$stmt = $mysqli->prepare("INSERT INTO Events (postID, title, location, from, to, description) VALUES ($post_id, ?, ?, ?, ?, ?)");
抱歉,如果它很容易看到什么错误
答案 0 :(得分:1)
准备中有两个保留关键字,它们是from
和to
所以只需用反引号将它们包围起来让mysql理解它们是字段
"location, ".
"`from`, ".
"`to`, ".
"description) ".