参数化查询不适用于 PHP mysql

Parameterized query not working with PHP mysql

我有 table 名称“页面”和“id、标题、slug”列,我正在研究核心 php 并尝试使用“参数化更新查询”,每当我执行我的查询然后它给我以下错误

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables

这是我的代码,我哪里错了?

$sql = "UPDATE pages SET title=? WHERE slug=? AND id=?";
$stmt= $conn->prepare($sql);
$stmt->bind_param($title,$slug,$headingid);
$stmt->execute();

在绑定参数时你应该定​​义它是什么类型,就像我猜的你的情况一样,标题是 string,slug 是 string,id 是 integer

$sql = "UPDATE pages SET title=? WHERE slug=? AND id=?";
$stmt= $conn->prepare($sql);
$stmt->bind_param("ssi", $title,$slug,$headingid);
$stmt->execute();