Im using dreamweaver with PHP.
I have items in my shopping cart which is then passed on to the transaction page.

How do i add the amount of items in the shopping cart?

Any help is appreciated!
Thanks!

Are you using a session to store the stuff in the cart or what? I'd suggest creating a session for the user with the following variables:

array $quantity
array $product

each element of those arrays will contain the info for an item. ($quantity[0] has the quantity of the first item and $product[0] has the name or item number or id of the product).

Are you using a session to store the stuff in the cart or what? I'd suggest creating a session for the user with the following variables:

array $quantity
array $product

each element of those arrays will contain the info for an item. ($quantity[0] has the quantity of the first item and $product[0] has the name or item number or id of the product).

Hey there.
Here's a code to my shopping cart

<?php require_once('../Connections/myDatabase.php'); ?>
<?php session_start(); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}


if ((isset($_POST['cartid'])) && ($_POST['cartid'] != "")) {
  $deleteSQL = sprintf("DELETE FROM cart WHERE cartid=%s",
                       GetSQLValueString($_POST['cartid'], "int"));

  mysql_select_db($database_myDatabase, $myDatabase);
  $Result1 = mysql_query($deleteSQL, $myDatabase) or die(mysql_error());

  $deleteGoTo = "DeleteSuccessfully.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
}

mysql_select_db($database_myDatabase, $myDatabase);
$query_Cart = "SELECT * FROM cart";
$Cart = mysql_query($query_Cart, $myDatabase) or die(mysql_error());
$row_Cart = mysql_fetch_assoc($Cart);
$totalRows_Cart = mysql_num_rows($Cart);
?>

<!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>Untitled Document</title>
<link href="../eb-main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
.style2 {font-size: small
}
body {
	background-color: #FFFFFF;
}
.style3 {color: #000000}
.style6 {font-size: 18px}
.style7 {color: #FFFFFF; font-size: medium; }
-->
</style>
</head>

<body>
<div id="wrapper">
  <div class="style1" id="banner">
    <div align="center">
      <p><img src="../Images/BooksInc Banner.jpg" width="751" height="300" /></p>
      <p>
        <map name="Map" id="Map">
          <area shape="rect" coords="2,0,145,63" href="../Pages/EventsMgt.html" />
          <area shape="rect" coords="154,0,283,63" href="../Pages/PA System.html" />
          <area shape="rect" coords="299,1,449,63" href="../Pages/RehearsalSuiteRental.html" />
          <area shape="rect" coords="651,-4,762,62" href="../Pages/BandTshirtDesign.html" />
        </map>
      <img src="../Images/BookHavenMenu.jpg" width="751" height="50" border="0" usemap="#Map2" />
<map name="Map2" id="Map2"><area shape="rect" coords="3,3,104,47" href="Home.php" />
<area shape="rect" coords="124,3,277,47" href="SelectUrBooks.php" />
<area shape="rect" coords="301,3,410,49" href="Transaction.php" />
</map></p>
    </div>
                                                                                 
    
                                                                                                                                                                             
    
                                                                                                                                                                                 
    
                                                                                                                                                                             
    
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></p>
  

    <p align="right">    
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    
    <a href="SelectUrBooks.php" class="style7">Continue Shopping</a>
<table width="83%" border="1">
      <?php do { ?>
      <form id="form1" name="form1" method="POST" action="">

        <tr>
          <td width="23%" scope="col"><span class="style6">
            <input name="cartid" type="hidden" id="cartid" value="<?php echo $row_Cart['cartid']; ?>" />
          <?php echo $row_Cart['title']; ?></span></td>
          <td width="23%" scope="col"><span class="style6"><?php echo $row_Cart['author']; ?></span></td>
          <td width="16%" scope="col"><span class="style6">$<?php echo $row_Cart['price']; ?></span></td>
          <td width="18%" scope="col"><span class="style6"><?php echo $row_Cart['category']; ?></span></td>
          <td width="5%" scope="col"><label>
            <input name="NoOfItems" type="text" id="NoOfItems" size="5" />
          </label></td>
          <td width="8%" scope="col"><input type="submit" name="Updatebtn" id="Updatebtn" value="Update" /></td>
          <td width="7%" scope="col"><label>
          <input type="submit" name="DeleteBtn" id="DeleteBtn" value="Delete" />
          </label></td>
        </tr>  </form>
        <?php } while ($row_Cart = mysql_fetch_assoc($Cart)); ?>
    </table>
  <p align="right">&nbsp;&nbsp;<span class="style6">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="ConfirmDelete.php"></a>      </span>
    &nbsp;&nbsp;&nbsp;
  
  <p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>

  <div class="style1" id="footer">
    <div align="center">
      <p class="style2">&nbsp;</p>
      <p class="style2">&nbsp;</p>
      <p class="style2">&nbsp;</p>
      <p class="style2">&nbsp;</p>
      <p class="style2">&nbsp;</p>
      <p class="style2">&nbsp;</p>
      <p class="style2"><span class="style3"><a href="Home.php">Home</a><span class="style1"> | </span><a href="SelectUrBooks.php">Select ur Books!</a> <span class="style1">| Transaction | Checkout | Transaction Summary</span></span></p>
      <p>&copy; Book Haven productions</p>
    </div>
  </div>
  </div>
</body>
</html>
<?php
mysql_free_result($Cart);
?>

If possible you could guide my through the steps cos im a beginner in PHP.

Hmm, you've got an input for the quantity. Did you add that in the hope of getting it to work? Does the cart work how it is without quantity? What do you actually mean by "add the amount of items in the shopping cart"?.

This article has been dead for over six months. Start a new discussion instead.