【发布时间】:2017-06-11 08:46:20
【问题描述】:
我正在开发一个带有数据库的 php 项目。我希望用户能够评论文章(我已经有一个用于创建文章的工作系统),但我无法在数据库中插入 cmets。代码如下:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$content = filter_input(INPUT_POST, 'new_entry', FILTER_SANITIZE_STRING);
$author = $_SESSION["username"];
$article_id = $_GET['article'];
$rating = 0;
if ($insert_stmt = $mysqli->prepare("INSERT INTO `entries` (`article_id`, `rating`, `content`, `author`) VALUES (?, ?, ?, ?)")) {
$insert_stmt->bind_param('iiss', $article_id, $rating, $content, $author);
// Führe die vorbereitete Anfrage aus.
if ($insert_stmt->execute()) {
header('Location: success.php');
} else {
header('Location: failure.php');
}
}
这总是将我引导到“failure.php”——这里有什么问题?
提前谢谢你!
【问题讨论】:
-
我建议您查看您的 http 服务器错误日志文件并使用
mysqli类提供的错误处理功能。 -
我收到此错误:
PHP Notice: Undefined index: article in C:\MAMP\htdocs\index.php on line 30 -
article是从查询字符串传递过来的吗?或者您可能需要使用 POST :$article_id = $_POST['article']; -
@b. desai
article像localhost/index.php?article=5这样写在 url 中,但$_GET['article']总是返回 null。