我遇到問題,當我嘗試刪除我在我的菜單頁中選擇的記錄後,我點擊刪除,標題顯示我該記錄已被刪除,作爲以及它顯示我的消息=刪除,但我意識到,該記錄仍然出現在我的菜單頁面,我也檢查了phpmyadmin,它也仍然存在,我想我沒有達到在刪除頁面選定的記錄,這裏是到目前爲止我的代碼: delete.phpPDO,無法刪除選定的記錄
<?php
include('koneksi.php');
$page_number = $_GET['page'];
<?php
include('koneksi.php');
$page_number = $_GET['page'];
$dbdit = new PDO('mysql:host=localhost;dbname=laundry','root','');
$results = $dbdit->prepare("SELECT COUNT(*) FROM konsumen");
$results->execute();
$get_total_rows = $results->fetch();
$results = $dbdit->prepare("DELETE FROM konsumen ORDER BY kode_pemesanan ASC LIMIT :page_number");
$results->bindValue(':page_number',$page_number);
$results->execute();
if($results){
header('location:menu.php?message=deleted&&?page=1');
}
menu.php
if($typeuser == 'admin'){
$item_per_page = 1;
$dbcon = new PDO('mysql:host=localhost;dbname=laundry','root','');
$results = $dbcon->prepare("SELECT COUNT(*) FROM konsumen");
$results->execute();
$get_total_rows = $results->fetch();
//breaking total records into pages
$pages = ceil($get_total_rows[0]/$item_per_page);
if(isset($_GET["page"])){
$page_number = filter_var($_GET["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
if(!is_numeric($page_number)){die('Invalid page number!<a href="?page=1"> Back! </a>');} //incase of invalid page number
}else{
$page_number = 1;
}
$position = (($page_number-1) * $item_per_page);
$results = $dbcon->prepare("SELECT * FROM konsumen ORDER BY kode_pemesanan ASC LIMIT $position, $item_per_page");
$results->execute();
while($row = $results->fetch()){
print_r ("<table>
<tr>
<td>Kode Pemesanan</td><td>:</td><td>".$row['kode_pemesanan']."</td></tr>
<tr><td>Atas Nama</td><td>:</td><td>".$row['atas_nama']."</td></tr>
<tr><td>Jumlah Baju</td><td>:</td><td>".$row['jmlhbaju']."</td></tr>
<tr><td>Jumlah Celana</td><td>:</td><td>".$row['jmlhcelana']."</td></tr>
<tr><td>Jumlah Jaket</td><td>:</td><td>".$row['jmlhjaket']."</td></tr>
<tr><td>Jumlah Jas</td><td>:</td><td>".$row['jmlhjas']."</td></tr>
<tr><td>Jumlah Dress</td><td>:</td><td>".$row['jmlhdress']."</td></tr>
<tr><td>Pengurus Pesanan</td><td>:</td><td>".$row['penguruspesanan']."</td></tr>
<tr><td>Status Pesanan</td><td>:</td><td>".$row['statuspesanan']."</td></tr>
<tr><td>Total Pesanan</td><td>:</td><td>".$row['totalpesanan']."</td>
</tr></table>
<br>
");
}
$min = 1;
if(isset($_GET["page"]) && $_GET["page"] > $min){
$previous = $page_number - 1;
echo "<a href='?page=$previous'>←Previous</a> ";
} else echo "<a href='?page=1'>←Previous</a> ";
echo "<a href='edit.php?page=$page_number'>Edit</a> ";
echo "<a href='delete.php?page=$page_number'>Delete</a> ";
if(isset($_GET["page"]) && $_GET["page"] < $pages){
$next = $page_number + 1;
echo "<a href='?page=$next'>Next→</a>";
} else echo "<a href='?page=$pages'>Next→</a>";
}
}
這裏有很多錯誤,這就解釋了爲什麼收到的答案如此糟糕!請至少爲我們提供包括主鍵在內的'konsumen'表定義。 –
抱歉我缺乏,所以konsumen表有kode_pemesanan作爲主鍵,atas_nama,jmlhbaju.jmlhcelana,jmlhjaket,jmlhjas,jmlhdress,penguruspesanan,statuspesanan和totalpesanan列,我在menu.php中使用分頁顯示konsumen表,它顯示好,它只能刪除選定的記錄,我想我無法達到選定的記錄。 – roger