Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

PHP / MySQL:Kesalahan setelah menghapus satu baris halaman PHP (difilter)

kasus ini sama dengan pertanyaanPHP / MySQL:Menampilkan beberapa kesalahan setelah berhasil memperbarui data

itu karena di dashboard_engineer2.php kode Anda akan menampilkan data dari database jika variabel dari, ke, tim diposting.

dari delete.php redirect ke dashboard_engineer2.php menjadi metode get dan data yang sebelumnya diposting hilang

ubah delete.php kode menjadi seperti ini

<?php
        $report_id = $_POST['report_id'];
        $from = $_POST['from'];
        $to = $_POST['to'];
        $team = $_POST['team'];

        $sql = "DELETE FROM ot_report WHERE report_id=:report_id";
        $query = $conn->prepare($sql);
        $query->execute(array(':report_id' => $report_id));

        // so that the data previously posted is taken
        // when redirecting to the dashboard_engineer2.php page 
        // even though it is a GET method

        header("Location: dashboard_engineer2.php?from={$from}&to={$to}&team={$team}");
?>

dan ada sedikit perubahan di dashboard_engineer2.php menjadi seperti ini

<?php

    // change the initial conditions to be like this
    // $_REQUEST will get data if there is data in POST or GET

    if(isset($_REQUEST["from"], $_REQUEST["to"], $_REQUEST["team"])){

        $from = $_REQUEST['from'];
        $to   = $_REQUEST['to'];
        $team = $_REQUEST['team'];

        $result = '';
        $query = "SELECT * FROM ot_report LEFT JOIN ot_users ON ot_report.badgeid = ot_users.badgeid WHERE ot_users.team_id = '".$team."' AND report_date BETWEEN '".$from."' AND '".$to."' ORDER BY ot_report.report_date DESC";

        $sql = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
        $sql -> execute();

        if($sql->rowCount() > 0){

        echo'

        <table class = "table-bordered" width = "100%">
        <thead>
        <tr>
        <th width = "10%"><input type="checkbox" id="checkAl"> All</th>
        <th width = "3%">id</th>
        <th width = "15%">Date</th>
        <th width = "30%">Task Name</th>
        <th width = "10%">Status</th>
        <th colspan = "2" width = "7%">Action</th>
        </tr>
        </thead>
        <tbody>';

            $i=0;

            while($row = $sql->fetch(PDO::FETCH_ASSOC)){

            $datereport = $row['report_date'];
            $datereport2 = strtotime($datereport);
            $report_date = date('d M Y', $datereport2);

            $report_id = $row["report_id"];

            echo'<tr>';
                echo '<td><input type="checkbox" id="checkItem" name="check[]" value='.$row['report_id'].'></td>';
                echo '<td>'.$report_id.'</td>';
                echo '<td>'.$report_date.'</td>';
                echo '<td>'.$row["task_name"].'</td>';
                echo '<td align="center"><strong>'.$row["report_status"].'</strong></td>';
                echo '<td align="center">';
                echo '<form action = "view_task/view_task.php" method = "post">';
                echo '<input type = "hidden" name = "report_id" value = "'.$report_id.'">';
                echo '<button type = "submit" class="btn-primary">View</button>';
                echo '</form>';

                echo "<form action = 'delete.php' method = 'post' onClick=\"return confirm('Do you want to remove team?')\">";
                echo '<input type = "hidden" name = "from" value = "'.$from.'">';
                echo '<input type = "hidden" name = "to" value = "'.$to.'">';
                echo '<input type = "hidden" name = "team" value = "'.$team.'">';
                echo '<input type = "hidden" name = "report_id" value = "'.$report_id.'">';
                echo '<button type = "submit" class="btn-danger">Delete</button>';
                echo '</form>';

                echo '</td>';
            echo '</tr>';
            $i++;

            }
            echo '<tr>';
                echo '<td><p align="center"><button type="submit" class="btn-danger btn-sm" name="save">DELETE</button></p></td>';
            echo '</tr>';
            echo '</form>';

        }
        else
        {
            echo '
            <table class = "table-bordered" width = "100%">
            <thead>
            <tr>
            <th width = "5%">id</th>
            <th width = "12%">Date</th>
            <th width = "23%">Task Name</th>
            <th width = "10%">Status</th>
            <th width = "7%">Action</th>
            </tr>
            <tr>
            <td colspan="5">No report found</td>
            </tr>';
        }
        echo '</body></table></div></div>';

        } 

?>


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. mengubah baris tabel menjadi kolom di mysql

  2. MySql, Postgres, Oracle dan SQLServer mengabaikan filter IS NOT NULL

  3. Kelompokkan berdasarkan minggu, bagaimana cara mendapatkan minggu kosong?

  4. Menutup koneksi aktif menggunakan RMySQL

  5. Mysqldump dari AWS RDS