Admin - Delete Product

 

This part also don't need much explanation. The process is simple. First we delete any references to this product from tbl_cart and tbl_order_item to maintain data integrity. Then remove the product images and thumbnail and finally remove the product from database.

The delete process is like this :

  1. Delete all references to this product from tbl_order_item
  2. Delete all references from tbl_cart
  3. Delete the product image and thumbnail
  4. Delete the product from database

And here is the code for deleteProduct() function that responsible for this process :

Source code : admin/product/processProduct.php

function deleteProduct()
{
   if (isset($_GET['productId']) && (int)$_GET['productId'] > 0) {
      $productId = (int)$_GET['productId'];
   } else {
      header('Location: index.php');
   }

   // remove any references to this product from
   // tbl_order_item and tbl_cart
   $sql = "DELETE FROM tbl_order_item
           WHERE pd_id = $productId";
   dbQuery($sql);

   $sql = "DELETE FROM tbl_cart
           WHERE pd_id = $productId";
   dbQuery($sql);

   // get the image name and thumbnail
   $sql = "SELECT pd_image, pd_thumbnail
           FROM tbl_product
           WHERE pd_id = $productId";

   $result =& dbQuery($sql);
   $row =& dbFetchAssoc($result);

   // remove the product image and thumbnail
   if ($row['pd_image']) {
      unlink(SRV_ROOT . 'images/product/' . $row['pd_image']);
      unlink(SRV_ROOT . 'images/product/' . $row['pd_thumbnail']);
   }

   // remove the product from database;
   $sql = "DELETE FROM tbl_product
           WHERE pd_id = $productId";
   dbQuery($sql);

   header('Location: index.php');
}

 

Find freelance programmers at ScriptLance.com - Search worldwide

Apple Computer Repair Seattle | craft supplies |
 

 

Admin - Edit Product PHP MySQL Shopping Cart Tutorial : Admin - Delete Product Admin - Order Management
Google
 
Web www.phpwebcommerce.com
 

At long last i'm finally able to update this site. Now the shopping cart can handle payment through paypal. As always you have any critiques, questions, comments or problems about this tutorial please tell me. Click here to send your feedback. And if you like this tutorial please link to this site. It will really help a lot :-)

 

"I made an extra $378 last week promoting just 1 site. Click here to see which site is it. Join today!"



PHP MySQL Shopping Cart Tutorial
Copyright © 2005 - 2010 www.phpwebcommerce.com