如果我删除此代码,我的页面会加载。但是如果我添加这个,我会从我的网络矩阵中获得HTTP错误500.
<?php
try {
if(isset(['submit'])) {
include('config.php');
$subject = $_POST['subject'];
$content = $_POST['editor1'];
$date = $_POST['date'];
$tags = $_POST['tags'];
$author = $_POST['author'];
$thumbnail = $_POST['thumbnail'];
$sql = "INSERT INTO articles (Subject, Content, Date, Author, Tags, Thumbnail) VALUES ('$subject','$content','$date','$author','$tags', '$thumbnail')";
$dbh->query($sql);
}
} catch(PDOException $e) {
echo $e->getMessage();
}
?>
答案 0 :(得分:2)
在第
行if (isset(['submit']))
缺少一个变量。您可能想要使用此行:
if(isset($_POST['submit']))
顺便说一句,您的SQL代码是为盲注SQL注入打开的。您应该解析参数或更好地使用预处理语句。
$stmt = $dbh->prepare("INSERT INTO articles (Subject, Content, Date, Author, Tags, Thumbnail) VALUES (':subject',':content',':date',':author',':tags', ':thumbnail')");
$stmt->bindParam(':subject', $subject);
$stmt->bindParam(':content', $content);
// ...
$stmt->execute();
答案 1 :(得分:2)
这不是声明:
if (isset(['submit']))
它应该是:
if (isset($_POST['submit']))
很有可能。
无论如何,你应该将参数绑定到查询,而不是将它们硬编码到它中。