簡體   English   中英

您能告訴我我的博客這段代碼有什么問題嗎?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM