Hello, I am having a bit of trouble being able to add a product to my shopcart.  My mysql database is setup correctly with the tables (User, ShopCart, ShopCartLine, Product, Order, OrderLine, etc.).
Right now I am using mode to pass the item number (productID) to the shopcart.  In my switch statement i am essentially getting that item number through the variable $action.  The problem is my query doesn't work.  Another problem is, I am not really sure of the correct way to setup session variables to be equal to the shopcartID in the shopcart table.  More specifically, I'm not exactly sure how I can use the session_id() function to implement this.  I currently hard coded a userid (from the user table) instead of passing the value through session.  That is another issue which I am not concerned with at the moment.  I just want to get this shopcart working in a reasonable fashion.  
Can somebody give me an idea of what I am doing wrong and or what I need to do to make this work properly?  I am really starting to get lost.  By the way, I do plan on adding cases to the switch statement for update and delete.  Thanks in advance everyone!  Here is the code:
Code: <?php include 'db-inc.php'; ?>
<?php include 'header.php'; ?>
<!-- <html>
 <head>
  <title>Shopping Cart Contents:</title>
  <style type="text/css">
   th { background-color: #999;}
   .odd_row { background-color: #EEE;  }
   .even_row { background-color: #FFF; }
  </style>
 <head>
<body>
 <h1> Ecommerce Multimedia Store </h1>
-->
<?php
$action = $_GET['mode'];
$ProductID = $_GET['itemno'];
$session = session_id();
$UserID = 1;
//connect to mysql
$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or 
    die ('Unable to connect. Check your connection parameters.');
//select database   
mysql_select_db(MYSQL_DB) or die(mysql_error($db));
switch ($action) {
case 'add' :
     if (!empty($ProductID)) {
         $query = 'INSERT INTO ShopCart( UserID )VALUES( $UserID )'; 
             mysql_query($query, $db) or die(mysql_error($db));
    $query = ' SELECT ShopCartID FROM ShopCart WHERE UserID = $UserID ORDER BY ShopCartID DESC LIMIT 1'
           
         $query = 'INSERT INTO ShopCartLine(ShopCartID, ProductID, Quantity)VALUES(" . $ShopcartID . '", "' . $ProductID. '", "', "' . $Quantity . '")';
             mysql_query($query, $db) or die(mysql_error($db));
          
   }
break;
}
$query = 'SELECT Product.ProductID, Quantity, Title, ListPrice
          FROM ShopCartLine JOIN Product ON ShopCartLine.ProductID = Product.ProductID
        JOIN ShopCart ON ShopCartLine.ShopCartID=ShopCart.ShopCartID
          WHERE ShopCart.ShopCartID = "' . $session . '"
          ORDER BY Product.ProductID ASC';
$result = mysql_query($query, $db) or die (mysql_error($db));
$rows = mysql_num_rows($result);
if ($rows == 1) {
     echo '<p>You currently have 1 product in your cart.</p>';
} else {
        echo '<p>You currently have ' . $rows . ' products in your cart.</p>';
}
if ($rows > 0) {
?>
<table style="width: 75%;">
  <tr>
   <th style="width: 100px;"> </th><th>Item Name</th><th><Quantity</th>
   <th>Price Each</th><th>Extended Price</th>
  </tr>
<?php
   $total = 0;
   $odd = true;
   while ($row = mysql_fetch_array($result)) {
      echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">';
           $odd = !$odd;
           extract($row);
?>
      <td><a href="shopcart.php?ProductID=<?php echo $ProductID;?>"><?php
        echo $Title; ?></a></td>
      <td>
       <form method="post" action="shopcartupdate.php">
        <div>
         <input type="text" name="Quantity" maxlength="2" size="2"
          value="<?php echo $Quantity; ?>"/>
         <input type="hidden" name="ProductID"
          value="<?php echo $ProductID; ?>"/>
         <input type="hidden" name="redirect" value="shopcart.php"/>
         <input type="submit" name=submit" value="Change Qty"/>
        </div>
       </form>
      </td>
      <td style="text-align: right;"> $<?php echo $ListPrice; ?></td>
      <td style="text-align: right;"> $<?php echo number_format
    ($ListPrice * $Quantity, 2); ?>
      </td>
     </tr>
    <?php
             $total = $total + $ListPrice * $Quantity;
      }
    ?>
</table>
<p> Your total before shipping is:
<strong>$<?php echo number_format($total, 2); ?></strong></p>
<form method="post" action="checkout.php">
 <div>
  <input type="submit" name="submit" value="Proceed to Checkout"
   style="font-weight: bold;"/>
 </div>
</form>
<form method="post" action="shopcartupdate.php">
 <div>
  <input type="hidden" name="redirect" value="index.php"/>
  <input type="submit" name="submit" value="Empty Cart" />
 </div>
</form>
<?php
}
?>
 <hr/>
<p><a href="index.php">< Back to main page</a></p>
</body>
</html>
<?php include 'footer.php'; ?>
How could I do this?
Ive got a simple lottery game, and am using an sql database to keep track of the numbers bought. But, when the person comes to buy the ticket, I have to replay to my process page which ticket they
Change Web page language
i doing this thing first time but i dont find any suitable solution for it. On the demand of user. I want to change my web site pages in user's language without without google translater. Can
Am I setting up my sites oldschool?
Ok,When I create a site I open a basic template that I have created that consists of a css file an index page and a few php inserts for the header, nav and footer.It works fine and I am happy with it
Help with parsing this html
Hi, I've got some html i just need a couple of strings from.. argh, it's freaking me out. I've tried a lot.Here is the html:Code: <div id="Tab01" style="overflow: auto;
login box shows up again after logging in 2nd login works
Hello,I am having trouble on my site Lockerz.rack111.com where when you login the login box when you hit submit clears and then when you type your info in again then the login box works.here is the
PHP Form to Variable.
Hi! I have written a HTML-form code in DreamWeaver CS3 (in a PHP doc) and I really need it to work soon :/I have a form:(<form name="form1" action=""
Snapshot from video
anyone knw how to make a snapshot maker from avi n mkv format.for example if i give a direct link (mysite.com/song.avi) then it will give a snapshot in jpg format
How to clone an SAP ECC using bacup tape on z/os?
We want to clone our production to a different SID using backup tape.
Database 'Validation'
Hi everyone,I'm trying to validate the password entered by the user with the password in the database. I've worked out that it checks the username fine (if the username doesn't exist it displays an
Remove Rows From Database ad
Hi All,I have this:Code: [Select]<?phpsession_start();include('../common/dbconnect.php');$stock_id = $_GET['stock_id'];$query='SELECT * FROM users_stocks WHERE user_id ="' .