-1

多亏了raina77ow,这个问题得到了解决。from 和 to 把准备好的语句弄乱了。

在过去的 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, ?, ?, ?, ?, ?)");

抱歉,如果它很容易看出问题所在

4

1 回答 1

1

您的准备中有两个保留关键字,它们是fromto所以只需用反引号将它们包围,让 mysql 理解它们是字段

    "location, ".
    "`from`, ".
    "`to`, ".
    "description) ". 
于 2013-05-15T15:41:35.797 回答