有人可以帮我理解这个错误吗?
致命错误:在第64行的C:\ MAMP \ htdocs \ MyCMS \ insert_posttwo.php中的非对象上调用成员函数bind_param()
<?php
$mysqli = mysqli_connect("localhost", "root", "root", "mycms");
if (isset($_POST['submit'] )) {
$post_author = $_POST['post_author'];
$stmt = $mysqli->prepare ("INSERT INTO 'posts' ('post_author') VALUES(?)");
$stmt->bind_param('s', $post_auth);
$post_auth = $post_author;
$stmt->execute();
echo "<script>alert('Post has been published')</script>";
echo "<script>window.open('insert_post','_self')</script>";
$stmt->close();
}
?>
答案 0 :(得分:3)
而不是单引号'
使用反引号`
来转义字段或表名。
$stmt = $mysqli->prepare ("INSERT INTO `posts` (`post_author`) VALUES(?)");
答案 1 :(得分:1)
更改此内容(对于您必须使用的列,不是单引号而是):
'posts'
为:
`posts`
此外,你必须创建一个对象,而不是程序方法,否则你不能这样做,所以使用它:
$mysqli = new mysqli_connect("localhost", "root", "root", "mycms");
//^^^ See here so you create a object
而且你必须这样关闭你的连接:
$mysqli->close();
//^^^^^ Close the connection and not the stmt