[英]Could you tell me what is wrong with this piece of code for my blog?
如果删除此代码,则会加载页面。 但是,如果添加此内容,则会从Web矩阵中收到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();
}
?>
在行中
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();
这不是声明:
if (isset(['submit']))
它应该是:
if (isset($_POST['submit']))
很有机会。
无论如何,您应该将参数绑定到查询,而不要将其硬编码到查询中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.