2017-04-23 98 views
0

我需要使用刪除按鈕從數據庫中刪除新聞文章。我寫了所有的代碼,但它給了我錯誤注意:未定義的索引:在第5行C:\ XAMPP \ htdocs \ PortalZaVijesti \ php \ delete.php中的acticleID。我沒有看到有什麼問題,所以你可以看看我的碼? admin.php的PHP從SQL中刪除數據庫使用按鈕

$dbc = mysqli_connect("localhost", "root", "", "news_portal") or die(mysql_error()); 
     $query = "SELECT * FROM news_site;"; 
     $result = mysqli_query($dbc, $query); 
     while ($row = mysqli_fetch_assoc($result)) { 
      echo "<p>".$row['title']; 
      echo "</p> 
       <form action='php/delete.php' method='post' class='deletePHP'> 
        <input type='hidden' name='articleID' value='".$row['id']."'/> 
        <input type='submit' name='delete' value='delete'/> 
       </form>; 

delete.php

$dbc = mysqli_connect("localhost", "root", "", "news_portal") or die(mysql_error()); 
    if(isset($_POST["delete"]) && !empty($_POST["articleID"])){ 
     $id = mysqli_real_escape_string($dbc, $_POST["acticleID"]); 
    } 

    $delquery = "DELETE FROM news_site WHERE ID='$id'"; 
    mysqli_query($dbc, $delquery) or die(mysqli_error($dbc)); 

    if(mysqli_affected_rows($dbc)){ 
     echo "It was really successful."; 
    } 

回答

2

我可以在delete.php中看到輸入錯誤。

在顯示的代碼的第3行上,「articleID」拼寫爲「acticleID」。這就是爲什麼你得到一個未定義的索引。

變化:

$id = mysqli_real_escape_string($dbc, $_POST["acticleID"]); 

到:

$id = mysqli_real_escape_string($dbc, $_POST["articleID"]); 
2

請修復線

$id = mysqli_real_escape_string($dbc, $_POST["acticleID"]); 

$id = mysqli_real_escape_string($dbc, $_POST["articleID"]); 

你已經輸入了錯誤的條款ArticleID