显示错误
注意:未定义的索引:clothCatId在C:xampphtdocsproject-clothadminlistProduct.php第21行产品列表…产品删除成功…注意:未定义变量:getProduct在C:xampphtdocsproject-clothadminlistProduct.php第58行序列号。品类类型布类品类品牌产品名称价格图片说明动作
在我的项目中,我点击这个链接来查看产品列表,也删除一些产品
<a href="listProduct.php?clothCatId=<?php echo $clothresult['clothCatId']?>" class="mwk-sub-item"><?php echo $clothresult['clothCatName'];?> </a>
当我点击下面的链接时,它会引导我进入该页面http://localhost/project-cloth/admin/listProduct.php?clothCatId=6
我通过写入
获取clothCatId=6来获取属于clothCatId 6的产品列表if(isset($_GET['clothCatId']) || $_GET['clothCatId']!=NULL){
$id=$_GET['clothCatId'];
$getProduct=$product->getAllProductByCategory($id);
}
,检索具有clothCatId=6的所有产品我的数据库数据
**Serial No. Category Type Cloth Category Brand Product Name Price Image Description Action**
3 men Men's... Formal Shirts Blackberrys Men Slim Fit Self De... 1500.00 The formal shirt is sometimes ... Edit || Delete
4 men Men's... Formal Shirts UNITED DENIM v... 222.00 dfergreg ... Edit || Delete
现在我愿意通过点击删除链接从数据库中删除一行
<td><a href="editProduct.php?productId=<?php echo $result['productId'];?>">Edit</a>|| <a onclick="return confirm('Are you sure to delete ?')" href="?delproduct=<?php echo $result['productId'];?>">Delete</a></td>
和获取产品id
<?php
if(isset($_GET['delproduct'])){
$id=$_GET['delproduct'];
$delProduct=$product->delProductById($id);
}
if(isset($_GET['clothCatId']) || $_GET['clothCatId']!=NULL){
$id=$_GET['clothCatId'];
$getProduct=$product->getAllProductByCategory($id);
}
?>
我有$_GET['delproduct']
和获取我想要删除的产品Id并通过在Product.php页面
public function delProductById($id){
$query="select * from tbl_product where productId='$id'";
$getData=$this->db->select($query);
if($getData){
while($delImage=$getData->fetch_assoc()){
$dellink=$delImage['image'];
unlink($dellink);
}
}
$delquery="delete from tbl_product where productId='$id'";
$delete_row=$this->db->delete($query);
if($delete_row){
$msg="Product deleted successfully...";
return $msg;
}else{
$msg="Product not deleted...";
return $msg;
}
}
当我试图删除记录时它不会删除并显示错误
注意:未定义的索引:clothCatId在C:xampphtdocsproject-clothadminlistProduct.php第21行产品列表…产品删除成功…注意:未定义变量:getProduct在C:xampphtdocsproject-clothadminlistProduct.php第58行序列号。品类类型布类品类品牌产品名称价格图片说明动作
listProduct.php
<?php
include 'header.php';
include 'sidebar.php';
include '../classes/Product.php';
?>
<?php
$product=new Product();
$fm=new Format();
?>
<?php
if(isset($_GET['delproduct'])){
$id=$_GET['delproduct'];
$delProduct=$product->delProductById($id);
}
if(isset($_GET['clothCatId']) || $_GET['clothCatId']!=NULL){
$id=$_GET['clothCatId'];
$getProduct=$product->getAllProductByCategory($id);
}
?>
<div class="box">
<h4>Product List...</h4>
<div class="block">
<?php
if(isset($delProduct)){
echo $delProduct;
}
?>
<table class="list-table">
<thead>
<tr>
<th>Serial No.</th>
<th>Category</th>
<th>Type</th>
<th>Cloth Category</th>
<th>Brand</th>
<th>Product Name</th>
<th>Price</th>
<th>Image</th>
<th>Description</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
if($getProduct){
$i=1;
while($result = $getProduct->fetch_assoc()){
?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo $result['catName'];?></td>
<td><?php echo $fm->textShorten($result['clothType'],5);?></td>
<td><?php echo $result['clothCatName'];?></td>
<td><?php echo $result['brandName'];?></td>
<td><?php echo $fm->textShorten($result['productName'],20);?></td>
<td><?php echo $result['price'];?></td>
<td><img src="<?php echo $result['image'];?>" height="40px" width="40px";></td>
<td><?php echo $fm->textShorten($result['description'],30);?></td>
<td><a href="editProduct.php?productId=<?php echo $result['productId'];?>">Edit</a>
|| <a onclick="return confirm('Are you sure to delete ?')" href="?delproduct=<?php echo $result['productId'];?>">Delete</a></td>
</tr>
<?php } } ?>
</tbody>
</table>
</div>
</div>
<?php
include 'footer.php';
?>
如何解决以上错误请帮助我。
点击删除链接后,我得到urlhttp://localhost/project-cloth/admin/listProduct.php?delproduct = 38
无法获取urlhttp://localhost/project-cloth/admin/listProduct.php?clothCatId = 6再次
这会导致警告:
if(isset($_GET['clothCatId']) || $_GET['clothCatId']!=NULL)
||
应为&&
。对于||
,只要第一个测试失败,它就执行第二个测试,这是警告,因为$_GET['clothCatId']
没有定义。
你可以组合它们:
if (!empty($_GET['clothCatId']))
empty()
检查变量是否设置,以及变量是否为空。
删除产品的链接只有delproduct
参数。您还应该发送类别ID以列出删除后的类别。
<a onclick="return confirm('Are you sure to delete ?')" href="?delproduct=<?php echo $result['productId'];?>&clothCatId=<?php echo $result['clothCatId'];?>">Delete</a>