我对 PHP 有点陌生,对 MySQLi 也很陌生,我试图在由 5 个变量组成的数据库中插入一行。
if($_POST['submit']) {
$title = mysqli_escape_string($_POST['title']);
$content = $_POST['content'];
$author = $_SESSION['fullname'];
$publishedtime = time();
$pageID = $_POST['pageid'];
$connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($connection->errno) {
printf("Connection failed: %s\n", $connection->error);
exit();
}
$author = $_SESSION['fullname'];
$publishedtime = time();
$q = "INSERT INTO posts (title, content, author, publishedtime, pageID) VALUES ('".$title."', '".$content."', '".$author."', '".$publishedtime."', '".$pageID."')";
if (!$dbc->query($q)) {
echo "INSERT failed: (" . $dbc->errno . ") " . $dbc->error;
}
echo "Newest user id = ",$dbc->insert_id;
$connection->close();
}
else {
addPostForm();
}
我得到这些错误:
警告:mysqli_escape_string() 需要 2 个参数,1 个在第 11 行的 /admin/manage.php 中给出
致命错误:在第 27 行的 /admin/manage.php 中的非对象上调用成员函数 query()
我可以很好地读取数据库,但无法插入其中。
谢谢