Updating the Quantity of an Item in a Shopper's Basket


Introduction.  This page will be a fairly simple processing script that deletes an item based on which button is pushed.
  • the item to be deleted is identified by id_basket_item
    • which is passed via a hidden textbox
  • we also need to make sure we get the change that has been posted in the textbox within the row on the basket display

The following PHP page should be called update_quantity.php and it should be uploaded to your firefox website.


<!-- update_quantity.php - updating the quantity of an item in a shopper's basket -->
// obtaining the id of the basket item the shopper wants to update
$id_basket_item = $_REQUEST["txt_id_basket_item"];
// connecting to the database on battcave.com
$link = mysql_connect($host, $user, $password);
// now we need to get all the basic info on the item
// in order to delete it from the basket_item table

$query_string = "UPDATE basket_item SET item_quantity = $txt_quantity WHERE id_basket_item = $id_basket_item";
mysql_db_query($db_name, $query_string, $link);


We now give some discussion of the code.

  • we start by obtaining the $id_basket_item using the $_REQUEST for what was passed in the hidden textbox from the basket.php
  • we make our connection to the database
  • we develop the query_string for the deletion based on the
    • id_basket_item
    • $txt_quantity passed from the form
  • we execute the query_string
  • we close the link
  • we redirect the shopper back to their basket