簡體   English   中英

使用php從表中刪除行的函數

[英]Function for deleting row from table using php

試圖解決我從生成的表中刪除行的問題。我有一個名為 report.php 的頁面,它顯示了數據庫中的所有行,並且有選項“刪除行”。 我的問題是當我點擊刪除沒有任何反應,它應該繼續 delete.php 文件。 現在我自己無法解決這個問題,也許你看到了我沒有看到的東西。 我沒有收到任何錯誤,所以我有點困惑。 謝謝你。

報告.php

<!DOCTYPE>
<html>
    <head>
        <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>


    <head>
    <body>
        <?php
            require_once '../include/functions.php';
            require_once '../include/db.php';

            $htmltable = "";

            $htmltable .= "<table>
            <tr>
                <th>ID</th>
                <th>Ime</th>
                <th>Ime slavljenika</th>
                <th>Datum</th>
                <th>Poruka</th>
                <th>Vreme prijave</th>
                <th>Obrisi</th>
            </tr>";


            $prep = $db->prepare("SELECT * from prijavljeni");
            $prep->execute();
            $prijavljeni = $prep->fetchAll();

            foreach($prijavljeni as $prijavljen => $row) {

                $htmltable.= '<tr>
                    <td>'.$row['prijavljeni_id'].'</td>
                    <td>'.$row['ime'].' </td>
                    <td>'.$row['ime_slavljenika'].' </td>
                    <td>'.$row['datum'] .'</td>
                    <td>'.$row['poruka'].' </td>
                    <td>'.$row['vreme'].'</td>
                    <td><a href="delete.php?prijavljeni_id=<?php echo $prijavljeni["prijavljeni_id"]; ?>Delete</a></td>
                </tr>';
               }

                $htmltable.='</table>';

                echo $htmltable;


        ?>

        <div>
            <button onclick="return email()">Posalji</button>
            <div id="emailporuka">
            </div><br><br>
        </div>
        <p align="center"><a href="logout.php">Logout</a></p>

        <script>
            function email(){

            $.ajax({
                  type:"post",
                  url: "email.php",

                  success: function(data){
                      //window.alert(data);
                      document.getElementById("emailporuka").innerHTML = data;
                  },
                  error: function (req, status, err) {
                console.log('Something went wrong', status, err);
                }
              })
              return false;
        }
        </script>

      </body>
</html>

刪除.php

<?php
    include('../include/db.php');
$prijavljeni_id=$_GET['prijavljeni_id'];
$result = $db->prepare("DELETE FROM prijavljeni WHERE prijavljeni_id= :prijavljeni_id");
$result->bindParam(':prijavljeni_id', $prijavljeni_id);
$result->execute();
header("location: izvestaj.php");

?> 

你只需要在你的 $htmltable 中改變它。 (在最后一個塊中附加字符串時出錯)。

          $htmltable.= '<tr>
                <td>'.$row['prijavljeni_id'].'</td>
                <td>'.$row['ime'].' </td>
                <td>'.$row['ime_slavljenika'].' </td>
                <td>'.$row['datum'] .'</td>
                <td>'.$row['poruka'].' </td>
                <td>'.$row['vreme'].'</td>
                <td><a href="delete.php?prijavljeni_id='.$prijavljeni['prijavljeni_id'].'">Delete</a></td>
            </tr>';

更新您的代碼

$result->bindParam(':prijavljeni_id', $prijavljeni_id);

$result->bindParam('prijavljeni_id', $prijavljeni_id);

記住一件事總是避免:在 bindParam 方法之前,但我們使用:在 prepareQuery 上來指示可替換值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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