单击按钮PHP PDO(使用分页)和MySQL删除行

当我单击“删除”按钮时,没有任何更改,并且记录也不会被删除。我在哪里做错了?我尝试了一些解决方案,但仍然无法解决。如果我能得到帮助,那就太好了。

  //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');

  ?>
repb123 回答:单击按钮PHP PDO(使用分页)和MySQL删除行

您没有正确传递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>';
本文链接:https://www.f2er.com/3019168.html

大家都在问