Mình có 1 trang code php để hiển thị sản phẩm ra ngoài. Bình thường mình vẫn xuất ra được sau mỗi lần thêm mới, nhưng không rõ hôm nay sao mình có xóa hết csdl và thêm lại thì không show được dữ liệu vừa thêm ra bên ngoài. Mình có kiểm tra code không sai chỗ nào, ai rõ nó vướng lỗi gì chỉ giúp mình được không ạ. Mình có search trên gg nhưng không hề có.
main_sp.php
<html>
<?php
if(isset($_GET["ac"]) && $_GET["ac"] == "them"){
include("modules/danhmuc/sanpham/them_san_pham.php");
}
elseif (isset($_GET["ac"]) && $_GET["ac"]=="sua") {
include("modules/danhmuc/sanpham/sua.php");
}
elseif(isset($_GET["ac"]) && $_GET["ac"]=="xoa"){
$id = $_GET["id"];
$sql_xoa = "delete from tb_sanpham where id_sanpham = '$id'";
mysqli_query($conn,$sql_xoa);
header("location:index.php?muc=dm_sp");
}
else{
$sql_dem = "select * from tb_sanpham";
$tong_sp = mysqli_num_rows(mysqli_query($conn,$sql_dem));
$ban_ghi_tren_trang = 6;
$tong_trang = ceil($tong_sp/$ban_ghi_tren_trang) ;
$trang_hien_thoi = isset($_GET["page"])?$_GET["page"]:1;
if($trang_hien_thoi >= $tong_trang) $trang_hien_thoi = $tong_trang;
if($trang_hien_thoi <=1) $trang_hien_thoi = 1;
$trang_bat_dau = ($trang_hien_thoi-1) * $ban_ghi_tren_trang;
$sql_show = "select * from tb_sanpham,tb_thuonghieu where tb_sanpham.id_thuonghieu = tb_thuonghieu.id_thuonghieu order by tb_sanpham.id_sanpham desc limit $trang_bat_dau,$ban_ghi_tren_trang";
$query_show = mysqli_query($conn,$sql_show);
?>
<div class="lietke">
<div class="them"><a href="index.php?muc=dm_sp&ac=them"><img src="./image/addIcon.png">Thêm Mới Sản Phẩm</a></div>
<form name="fmr_mainsp" method="post" enctype="multipart/form-data">
<h3>Danh Sách Sản Phẩm</h3>
<table border="1px" cellspacing="1">
<tr>
<th>ID</th>
<th>Tên Sản Phẩm</th>
<th>Thương Hiệu</th>
<th>Hình Ảnh</th>
<th>Giá Bán</th>
<th>Số Lượng</th>
<th colspan="2">Thao Tác</th>
</tr>
<?php
$i =1;
while($data_show = mysqli_fetch_array($query_show)){
?>
<tr>
<td><?php echo $i;?></td>
<td><?php echo $data_show["ten_sanpham"]; ?></td>
<td><?php echo $data_show["ten_thuonghieu"]; ?></td>
<td><img src="modules/danhmuc/sanpham/Image_sp/<?php echo $data_show["anh_sanpham"]; ?>" width="60px" height="80px"></td>
<td><?php echo number_format($data_show["gia_sanpham"]) ." VNĐ"; ?></td>
<td><?php echo $data_show["soluong_sanpham"]; ?></td>
<td><a href="index.php?muc=dm_sp&ac=sua&id=<?php echo $data_show["id_sanpham"]; ?>"><img src="./image/editIcon.png" width="32" height="32"></a></td>
<td><a href="index.php?muc=dm_sp&ac=xoa&id=<?php echo $data_show["id_sanphan"]; ?>"><img src="./image/deleteIcon.png" width="32" height="32"></a></td>
</tr>
<?php
$i++;
}
?>
</table>
<?php
if($tong_trang>1 && $trang_hien_thoi >1){
$page = $trang_hien_thoi-1;
?>
<div class="page"><a href="index.php?muc=dm_sp&page=<?php echo $page; ?>">Prev|</a></div>
<?php
}
for($i =1 ; $i <= $tong_trang;$i++){
if($i == $trang_hien_thoi){
?>
<span class="page"><?php echo $i; ?></span>
<?php
}
else{
?>
<div class="page"><a href="index.php?muc=dm_sp&page=<?php echo $i; ?>"><?php echo $i; ?></div>
<?php
}
}
if($trang_hien_thoi < $tong_trang && $tong_trang>1){
$page = $trang_hien_thoi+1;
?>
<div class="page"><a href="index.php?muc=dm_sp&page=<?php echo $page; ?>">|Next</a></div>
<?php
}
?>
</form>
</div>
<?php
}
?>
</html>