【问题标题】:Deleting Row with clicking on button PHP PDO (using Pagination) and MySQL [closed]通过单击按钮 PHP PDO(使用分页)和 MySQL 删除行 [关闭]
【发布时间】:2019-11-27 18:35:36
【问题描述】:

当我点击删除按钮时,没有任何变化,记录也不会被删除。我在哪里做错了?我尝试了一些解决方案,但仍然无法解决。如果我能得到帮助会很好。

  //thats the indexcards.php  


  while ($row = $sql->fetch(PDO::FETCH_ASSOC)){ 
    echo'<tr>
    <td>'.$row["ModuleID"] .'</td>

    <td>'.$row["ModuleName"]. '</td> 

    <td>'.$row["IndexcardSuggestionID"]. '</td> 

    <td>'.$row["FrontContent"]. '</td>

    <td>'.$row["BackContent"]. '</td> 

    <td> <a href=../Delete/delete.php?id=". row[\"IndexcardSuggestionID\"]. "\'>DELETE</a></td>

    <td><input type="button" name="accept" value="Accept"></td>

    <td><input type="button" name="conditionally" value="Conditionally"></td> 

    </tr>';



   // And thats the delete.php


    <?php

session_start();

include_once '../../config/connection.php';

$database = new Database();
$db = $database->getConnection();

$id = $_GET['id'];



 $sql = "DELETE FROM IndexcardSuggestions WHERE IndexcardSuggestionsID = $id";


 header('Location: ../Suggestions/indexcards.php');

  ?>

【问题讨论】:

  • 您的代码易受 SQL 注入攻击。您应该使用准备好的语句。

标签: php html mysql button sql-delete


【解决方案1】:

您没有正确传递 ID。请注意,您不能在单引号内使用 PHP 变量,所有内容都被视为字符串。此外,如评论中所述,您的代码容易受到MySQL injection 的攻击。

echo'<tr>
        <td>'.$row["ModuleID"] .'</td>

        <td>'.$row["ModuleName"]. '</td>

        <td>'.$row["IndexcardSuggestionID"]. '</td>

        <td>'.$row["FrontContent"]. '</td>

        <td>'.$row["BackContent"]. '</td>

        <td> <a href=../Delete/delete.php?id=".' . $row["IndexcardSuggestionID"]. '"\'>DELETE</a></td>

        <td><input type="button" name="accept" value="Accept"></td>

        <td><input type="button" name="conditionally" value="Conditionally"></td>

        </tr>';

【讨论】:

  • 准备好的语句很有帮助。现在明白了
猜你喜欢
  • 1970-01-01
  • 2015-02-03
  • 2011-04-29
  • 2016-10-01
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 2020-10-19
  • 1970-01-01
相关资源
最近更新 更多