任何人都可以帮我准备好我的准备声明吗?
我无法弄清楚这里出了什么问题
$stmt = $dbCon->prepare("INSERT INTO rock_news (heading, subheading, description, author) VALUES (?, ?, ?, ?)");
$stmt->bind_param("sss", $heading, $subheading, $description, $author);
$stmt->execute();
// set parameters and execute
$heading = $_POST['heading'];
$subheading = $_POST['subheading'];
$description = $_POST['description'];
$author = $_POST['author'];
$stmt->execute();
这项工作?
$sql ="INSERT INTO rock_news (heading, subheading, description, author) VALUES ('$_POST[heading]','$_POST[subheading]','$_POST[description]','$_POST[author]')";
if ($dbCon->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $dbCon->error;
}
?>
尝试连接时出现此错误
注意:使用未定义的常量标题 - 在第6行ssaddas的/xxx/sandbox/royalRockFestival/pages/send_form.php中假定为'heading'警告:mysqli_stmt :: bind_param():类型定义字符串中的元素数量's' t匹配第9行/xxx/sandbox/royalRockFestival/pages/send_form.php中绑定变量的数量
这是什么意思?
答案 0 :(得分:1)
在$stmt->bind_param("sss", $heading, $subheading, $description, $author);
行中,
你有4个参数但只有3个绑定类型("sss"
),它代表字符串,字符串,字符串。只需将其更改为"ssss"
即可。