Thiết kế website bán hàng | Trang Admin: Quản lý nhận xét của sản phẩm

Ở bài này chúng ta cần làm được: danh sách các nhận xét và chỉnh sửa thông tin, không cần thêm mới

Tạo file với tên comment.php

<?php include ‘inc_checklogin.php’;
include ‘../includes/functions.php’;
if($_GET[‘delete’]){
mysql_query(“DELETE FROM lesson_comment WHERE id = “.intval($_GET[‘delete’]));
header(‘location: comment.php’);
exit();

}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Shop Admin</title>
<link rel=”stylesheet” type=”text/css” href=”style.css”>
</head>

<body>
<?php include ‘inc_header.php’;?>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”18%” valign=”top”><?php include ‘inc_menu.php’;?></td>
<td width=”82%” valign=”top”><h2>Nhận xét</h2>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr bgcolor=”#CCCCCC”>
<th width=”59%”>Tên</th>
<th width=”28%”>Tên sản phẩm</th>
<th width=”13%”>công cụ</th>
</tr>
<?php
$sql = “SELECT c.*,p.name pro_name,p.catid FROM lesson_comment c,lesson_product p WHERE p.id = c.proid”;
$total_sql = mysql_query($sql);
$total = mysql_num_rows($total_sql);

$limit = 10;
$page = intval($_GET[‘p’]);
$start = $page * $limit;
$sql .= ” LIMIT $start,$limit”;

$sql = mysql_query($sql);
while($rs = mysql_fetch_assoc($sql)){ ?>
<tr>
<td><?php echo $rs[‘name’];?></td>
<td><a href=”product_edit.php?id=<?php echo $rs[‘proid’];?>&parentid=<?php echo $rs[‘catid’];?>”><?php echo$rs[‘pro_name’];?></a></td>
<td align=”center”><a href=”comment_edit.php?id=<?php echo $rs[‘id’];?>”>Edit</a> <a href=”comment.php?delete=<?php echo $rs[‘id’];?>”>Xóa</a></td>
</tr>
<?php } ?>
<tr bgcolor=”#eeeeee”>
<td><?php
$url = ‘comment.php’;
echo page($url,$total,$page,$limit);
?></td>
<td align=”center”>&nbsp;</td>
<td align=”center”>&nbsp;</td>
</tr>
</table></td>
</tr>
</table>
<?php include ‘inc_footer.php’;?>
</body>

</html>

file để xử lí quá trình sửa, tạo file comment_edit.php

<?php include ‘inc_checklogin.php’;
if($_POST){
$name = addslashes($_POST[‘name’]);
$comment = addslashes($_POST[‘comment’]);
mysql_query(“UPDATE lesson_comment SET name = ‘$name’,comment = ‘$comment’ WHERE id = “.intval($_GET[‘id’]));
header(‘location: comment.php’);
exit();
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Shop Admin</title>
<link rel=”stylesheet” type=”text/css” href=”style.css”>
</head>

<body>
<?php include ‘inc_header.php’;?>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”18%”><?php include ‘inc_menu.php’;?></td>
<td width=”82%”><h2><?php echo $_GET[‘id’]==’insert’?’New’:’Update’;?> Comment</h2>

<form id=”form1″ name=”form1″ method=”post” action=””>
<?php
$result = array();
if(is_numeric($_GET[‘id’])){
$sql = “SELECT * FROM lesson_comment WHERE id = “.$_GET[‘id’];

$sql = mysql_query($sql);
$result = mysql_fetch_assoc($sql);
}
?>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”19%”>Name</td>
<td width=”81%”><input type=”text” name=”name” id=”name” value=”<?php echo $result[‘name’];?>” /></td>
</tr>
<tr>
<td>Comment</td>
<td><textarea name=”comment” cols=”50″ rows=”5″ id=”comment”><?php echo $result[‘comment’];?></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type=”submit” name=”button” id=”button” value=”Submit” /></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<?php include ‘inc_footer.php’;?>
</body>

</html>

Chúc bạn thành công,
Thiết kế số
FOLLOW US

Leave a Reply

Your email address will not be published. Required fields are marked *