shopping cart problem

Discussion in 'PHP' started by ravi951, Aug 30, 2011.

  1. #1
    hi all,
    i am working on a simple shopping cart program.I have created one database and stored images too in database.
    i am not getting executed the shopping cart.tell me what went wrong.
    below is my database i have created......
    it is saved as "shopping.sql"
    [HIGHLIGHT="SQL"]

    -- Table structure for table `customers`

    CREATE TABLE IF NOT EXISTS `customers`(
    `serial` int(11) NOT NULL auto_increment,
    `name` varchar(20) collate latin1_general_ci NOT NULL,
    `email` varchar(80) collate latin1_general_ci NOT NULL,
    `address` varchar(80) collate latin1_general_ci NOT NULL,
    `phone` varchar(20) collate latin1_general_ci NOT NULL,
    PRIMARY KEY(`serial`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;

    -- Table structure for table `orders`

    CREATE TABLE IF NOT EXISTS `orders` (
    `serial` int(11) NOT NULL auto_increment,
    `date` date NOT NULL,
    `customerid` int(11) NOT NULL,
    PRIMARY KEY(`serial`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;
    -- Dumping data for table `orders`

    -- Table structure for table `order_detail`
    CREATE TABLE IF NOT EXISTS `order_detail` (
    `orderid` int(11) NOT NULL,
    `productid` int(11) NOT NULL,
    `quantity` int(11) NOT NULL,
    `price` float NOT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
    -- Dumping data for table `order_detail`

    -- Table structure for table `products`
    CREATE TABLE IF NOT EXISTS `products`(
    `serial` int(11) NOT NULL auto_increment,
    `name` varchar(20) collate latin1_general_ci NOT NULL,
    `description` varchar(255) collate latin1_general_ci NOT NULL,
    `price` float NOT NULL,
    `picture` varchar(80) collate latin1_general_ci NOT NULL,
    PRIMARY KEY(`serial`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=7;

    INSERT INTO `products` (`serial`, `name`, `description`, `price`, `picture`) VALUES
    (1, 'View Sonic LCD', '19" View Sonic Black LCD, with 10 months warranty', 250, 'images/lcd.jpg'),
    (2, 'IBM CDROM Drive', 'IBM CDROM Drive', 80, 'images/cdrom-drive.jpg'),
    (3, 'Laptop Charger', 'Dell Laptop Charger with 6 months warranty', 50, 'images/charger.jpg'),
    (4, 'Seagate Hard Drive', '80 GB Seagate Hard Drive in 10 months warranty', 40, 'images/hard-drive.jpg'),
    (5, 'Atech Mouse', 'Black colored laser mouse. No warranty', 5, 'images/mouse.jpg'),
    (6, 'Nokia 5800', 'Nokia 5800 XpressMusic is a mobile device with 3.2" widescreen display brings photos, video clips and web content to life', 299, 'images/mobile.jpg');


    below is my database connection saved ad "db.php"
    
    <?php
    mysql_connect("localhost","root","") or die("mysql_error()");
    mysql_select_db("shopping") or die("mysql_error()");
    session_start();
    ?>
    
    Code (markup):
    below is my "functions.php" program
    
    <?php
    function get_product_name($pid)
     {
      $result=mysql_query("select name from products where serial=$pid");
      $row=mysql_fetch_array($result);
      return $row['name'];
     }
    
    function get_price($pid)
     {
      $result=mysql_query("select price from products where serial=$pid");
      $row=mysql_fetch_array($result);
      return $row['price'];
     }
    
    function remove_product($pid)
     {
      $pid=intval($pid);
      $max=count($_SESSION['cart']);
      for($i=0;$i<$max;$i++)
       {
        if($pid==$_SESSION['cart'][$i]['productid'])
         {
    	unset($_SESSION['cart'][$i]);
    	break;
         }
       }
        $_SESSION['cart']=array_values($_SESSION['cart']);
     }
    
    function get_order_total()
    {
     $max=count($_SESSION['cart']);
     $sum=0;
     for($i=0;$i<$max;$i++)
     {
      $pid=$_SESSION['cart'][$i]['productid'];
      $q=$_SESSION['cart'][$i]['qty'];
      $price=get_price($pid);
      $sum+=$price*$q;
     }
    return $sum;
    }
    
    function addtocart($pid,$q)
     {
      if($pid<1 or $q<1) return;
      if(is_array($_SESSION['cart']))
       {
        if(product_exists($pid)) return;
        $max=count($_SESSION['cart']);
        $_SESSION['cart'][$max]['productid']=$pid;
        $_SESSION['cart'][$max]['qty']=$q;
       }
        else
         {
          $_SESSION['cart']=array();
          $_SESSION['cart'][0]['productid']=$pid;
          $_SESSION['cart'][0]['qty']=$q;
         }
     }
    	
    function product_exists($pid)
     {
      $pid=intval($pid);
      $max=count($_SESSION['cart']);
      $flag=0;
      for($i=0;$i<$max;$i++)
      {
       if($pid==$_SESSION['cart'][$i]['productid'])
        {
         $flag=1;
         break;
        }
      }
    return $flag;
     }
    ?>
    
    Code (markup):
    below is the "products.php".this is the program from where my shopping cart begins.here i am not getting displayed the product image,price.and "addtocart" button is also not executing.
    
    <?php
    include("db.php");
    include("functions.php");
    if($_REQUEST['command']=='add' && $_REQUEST['productid']>0)
     {
      $pid=$_REQUEST['productid'];
      addtocart($pid,1);
      header("location:shoppingcart.php");
      exit();
     }
    ?>
    <!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>Products</title>
    <script type="text/javascript">
    function addtocart(pid)
     {
      document.form1.productid.value=pid;
      document.form1.command.value='add';
      document.form1.submit();
     }
    </script>
    </head>
    <body>
    <form name="form1">
    <input type="hidden" name="productid" />
    <input type="hidden" name="command" />
    </form>
    <div align="center">
    <h1 align="center">Products</h1>
    <table border="0" cellpadding="2px" width="600px">
    <?php
     $result=mysql_query("select * from products");
     while($row=mysql_fetch_array($result))
      {
    ?>
       <tr>
        <td><img src="<?php=$row['picture']?>" /></td>
        <td><b>       <?php=$row['name']?></b><br />
                      <?php=$row['description']?><br />
    				  Price:<big style="color:green">
                     $<?php=$row['price']?></big><br /><br />
           <input type="button" value="Add to Cart" onclick="addtocart(<?php=$row['serial']?>)" />
    	</td>
    	</tr>
          <tr><td colspan="2"><hr size="1" /></td></tr>
           <?php
     } 
           ?>
    </table>
    </div>
    </body>
    </html>
    
    Code (markup):
    below is my "shoppingcart.php" program after selecting no of items for shopping the below program id displayed.
    
    <?php
    include("db.php");
    include("functions.php");
    if($_REQUEST['command']=='delete' && $_REQUEST['pid']>0)
     {
      remove_product($_REQUEST['pid']);
     }
    else if($_REQUEST['command']=='clear')
     {
      unset($_SESSION['cart']);
     }
    else if($_REQUEST['command']=='update')
     {
      $max=count($_SESSION['cart']);
      for($i=0;$i<$max;$i++)
       {
        $pid=$_SESSION['cart'][$i]['productid'];
        $q=intval($_REQUEST['product'.$pid]);
        if($q>0 && $q<=999)
         {
    	$_SESSION['cart'][$i]['qty']=$q;
         }
    	else
         {
    	  $msg='Some products not updated!,quantity must be a number between 1 and 999';
    	 }
       }
     }
    ?>
    <!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>Shopping Cart</title>
    <script type="text/javascript">
    function del(pid)
    {
     if(confirm('Do you really mean to delete this item?'))
       {
        document.form1.pid.value=pid;
        document.form1.command.value='delete';
        document.form1.submit();
       }
    }
    
    function clear_cart()
    {
     if(confirm('This will empty your shopping cart, continue?'))
      {
        document.form1.command.value='clear';
        document.form1.submit();
      }
    }
    
    function update_cart()
     {
      document.form1.command.value='update';
      document.form1.submit();
     }
    
    </script>
    </head>
    <body>
    <form name="form1" method="post">
    <input type="hidden" name="pid" />
    <input type="hidden" name="command" />
    <div style="margin:0px auto; width:600px;" >
      <div style="padding-bottom:10px">
       <h1 align="center">Your Shopping Cart</h1>
       <input type="button" value="Continue Shopping" onclick="window.location='products.php'" />
      </div>
        <div style="color:#F00"><?php=$msg?></div>
        <table border="0" cellpadding="5px" cellspacing="1px" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; background-color:#E1E1E1" width="100%">
        <?php
        if(is_array($_SESSION['cart']))
          {
            echo '<tr bgcolor="#FFFFFF" style="font-weight:bold">
    	    <td>Serial</td>
    	    <td>Name</td>
    		<td>Price</td>
    		<td>Qty</td>
    	    <td>Amount</td>
    		<td>Options</td></tr>';
    	    $max=count($_SESSION['cart']);
    	     for($i=0;$i<$max;$i++)
              {
    		 $pid=$_SESSION['cart'][$i]['productid'];
    		 $q=$_SESSION['cart'][$i]['qty'];
    		 $pname=get_product_name($pid);
    		 if($q==0) continue;
    	?>
      <tr bgcolor="#FFFFFF"><td><?php=$i+1?></td><td><?php=$pname?></td>
         <td>$ <?php=get_price($pid)?></td>
         <td><input type="text" name="product<?php=$pid?>" value="<?php=$q?>" maxlength="3" size="2" /></td>
         <td>$ <?php=get_price($pid)*$q?></td>
         <td><a href="javascript:del(<?php=$pid?>)">Remove</a></td>
      </tr>
     <?php
     }
     ?>
    	<tr>
    	<td><b>Order Total: $<?php=get_order_total()?></b></td>
    	<td colspan="5" align="right">
    	<input type="button" value="Clear Cart" onclick="clear_cart()">
        <input type="button" value="Update Cart" onclick="update_cart()">
        <input type="button" value="Place Order" onclick="window.location='billing.php'">
    	</td>
    	</tr>
      <?php
          }
    	else
         {
    	echo "<tr bgColor='#FFFFFF'><td>There are no items in your shopping cart!</td>";
    	}
    	?>
         </table>
       </div>
    </form>
    </body>
    </html>
    
    Code (markup):
    this is the final "billing.php".if only user name is given it will execute.
    but i want all things to be mandatory.
    
    <?php
    include("db.php");
    include("functions.php");
    if($_REQUEST['command']=='update')
    {
      $name=$_REQUEST['name'];
      $email=$_REQUEST['email'];
      $address=$_REQUEST['address'];
      $phone=$_REQUEST['phone'];
      $result=mysql_query("insert into customers values('','$name','$email','$address','$phone')");
      $customerid=mysql_insert_id();
      $date=date('Y-m-d');
      $result=mysql_query("insert into orders values('','$date','$customerid')");
      $orderid=mysql_insert_id();	
      $max=count($_SESSION['cart']);
      for($i=0;$i<$max;$i++)
       {
        $pid=$_SESSION['cart'][$i]['productid'];
        $q=$_SESSION['cart'][$i]['qty'];
        $price=get_price($pid);
        mysql_query("insert into order_detail values($orderid,$pid,$q,$price)");
       }
    	die('Thank You! your order has been placed!');
    }
    ?>
    <!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>Billing Info</title>
    <script type="text/javascript">
     function validate()
      {
    	var f=document.form1;
    	 if(f.name.value=='')
          {
    		alert('Your name is required');
    		f.name.focus();
    		return false;
    	  }
    		f.command.value='update';
    		f.submit();
     }
    </script>
    </head>
    <body>
    <form name="form1" onsubmit="return validate()">
        <input type="hidden" name="command" />
    	<div align="center">
            <h1 align="center">Billing Info</h1>
            <table border="0" cellpadding="2px">
             <tr><td>Order Total:</td><td><?=get_order_total()?></td></tr>
             <tr><td>Your Name:</td><td><input type="text" name="name" /></td></tr>
             <tr><td>Address:</td><td><input type="text" name="address" /></td></tr>
             <tr><td>Email:</td><td><input type="text" name="email" /></td></tr>
             <tr><td>Phone:</td><td><input type="text" name="phone" /></td></tr>
             <tr><td>&nbsp;</td><td><input type="submit" value="Place Order" /></td></tr>
            </table>
    	</div>
    </form>
    </body>
    </html>
    
    Code (markup):
    tell me what went wrong why it is not executing....
     
    ravi951, Aug 30, 2011 IP
  2. programmer_best1

    programmer_best1 Well-Known Member

    Messages:
    282
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    133
    #2
    who don't you attach the full script for us so we can help ?
     
    programmer_best1, Sep 1, 2011 IP
  3. ravi951

    ravi951 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    in my last "billing.php" field only the name field is mandatory but i want other fields also to be mandatory i.e., email should be of correct format and phone no should be of exactly 10 digits no.
    tell me how to do it....
     
    ravi951, Sep 1, 2011 IP
  4. ravi951

    ravi951 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    here is my full shopping cart code.i am not getting the items i have choosen.
    kindly tell me what went wrong..
    
    <!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>
    <title> JavaScript jQuery</title>
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
    		  // call the cart function
    			$("#sc_cart").smartCart();
    		}); 
    	</script>
    <link rel="stylesheet" type="text/css" href="css/cart.css" />
    </head>
    <body>
     <center><h2>Select Your products</h2></center>
    <form  method="post" action="results.php">
     
     <div id="smartcart" class="Container">         		
        <div id="sc_productlist" class="scProductList">
           <div class="ProductListItem"> 
     		    <table border="0" cellpadding="2" cellspacing="2">
                    <tr>
                      <td rowspan="3"><img width="100px" src="images/product0.jpg" /></td>
                      <td><strong><span id="prod_name100">Apple IPhone 3G</span></strong></td>
                    </tr>
                    <tr>
                      <td><label>Price:</label> $<span id="prod_price100">1450.75</span></td>
                    </tr>               
                    <tr>
                      <td><label>Quantity:</label>
                        <input name="prod_qty" class="Text" id="prod_qty100" value="1" size="3" type="text">
     					<input type="button" rel="100" class="ItemButton Btn" value="Add Product"></td>
                    </tr>              
                </table>
            </div>					
    	<hr/>
    		<div class="ProductListItem"> 
            	<table border="0" cellpadding="2" cellspacing="2">
                    <tr>
                      <td rowspan="3"><img width="100px" src="images/product1.jpg" /></td>
                      <td><strong><span id="prod_name101">Ice Pot</span></strong></td>
                    </tr>
                    <tr>
                      <td><label>Price:</label> $<span id="prod_price101">10.25</span></td>
                    </tr>               
                    <tr>
                      <td><label>Quantity:</label>
                        <input name="prod_qty" class="Text" id="prod_qty101" value="1" size="3" type="text">
      					<input type="button" rel="101" class="ItemButton Btn" value="Add Product"></td>
                    </tr>              
                </table>
            </div>  
               <hr/>         
    		<div class="ProductListItem"> 
                <table border="0" cellpadding="2" cellspacing="2">
                    <tr>
                      <td rowspan="3"><img width="100px" src="images/product2.jpg" /></td>
                      <td><strong><span id="prod_name102">Style Stand</span></strong></td>
                    </tr>
                    <tr>
                      <td><label>Price:</label> $<span id="prod_price102">6.15</span></td>
                    </tr>               
                    <tr>
                      <td><label>Quantity:</label>
                        <input name="prod_qty" class="Text" id="prod_qty102" value="1" size="3" type="text">
      					<input type="button" rel="102" class="ItemButton Btn" value="Add Product"></td>
                    </tr>              
                </table>          
    		</div>  
          <hr/>
            <div class="ProductListItem"> 
            	<table border="0" cellpadding="2" cellspacing="2">
                    <tr>
                      <td rowspan="3"><img width="100px" src="images/product3.jpg" /></td>
                      <td><strong><span id="prod_name103">Coffe Maker</span></strong></td>
                    </tr>
                    <tr>
                      <td><label>Price:</label> $<span id="prod_price103">120.35</span></td>
                    </tr>               
                    <tr>
                      <td><label>Quantity:</label>
                        <input name="prod_qty" class="Text" id="prod_qty103" value="1" size="3" type="text">
      					<input type="button" rel="103" class="ItemButton Btn" value="Add Product"></td>
                    </tr>              
                </table>            
    		</div>  
            </div>
    	</div>	
         
        <div id="sc_cart" class="scCart">
          <select id="product_list" name="product_list[]" style="display:none;" multiple="multiple">
          </select>               
              <div class="CartListHead">
                    <table width='50%'>
    				<tr>
                      <td width='100px'>Product</td>
                      <td width='100px'>Quantity</td>
                      <td width='150px'>Amount($)</td>
                    </tr>
    				</table>
              </div>
                
        <div id="sc_cartlist" class="scCartList">
    	</div>
            <div class="CartListHead">
               <table width='100%'>
    		   <tr>
                  <td>
                  <span id="message"></span>
    			  </td>
                    <td width='100px'>Subtotal ($):</td>
                    <td width='120px'><span id="subtotal"></span></td>
                </tr>
    		  </table>
            </div>
                <br>
     <input style="width:200px;height:35px;float:right;" type="submit" class="Btn" value="Checkout">
              </div>
     </form>
    </body>
    </html>
    
    Code (markup):
    this is my cart.css.
    
    body {
      font : normal 12px Verdana, Helvetica, sans-serif;
      color:#0464BB; 
      margin:0;
      padding:0;
    }
    .Container {
    	padding: 5px;
    	border: 1px solid #E0E0E0; 
    	width: auto;
    	height:auto;
    	margin: 5px; 
    	float:left;   
        font-family : Verdana, Helvetica, sans-serif;
    	font-size: 12px;  
        position:relative;
    	left:5%;
        right:5%;
    }
    /*.scTitle {
    	padding: 2px; 
    	float:left;
    	font-weight: bold; 
    	margin-bottom: 3px; 
    	float:left;
    }  */
    .Btn {
      background : #5A5655;
      color      : #FFFFFF;
      margin     : 0;
      padding    : 1px 5px 1px 5px;
      text-align : center;
      border     : 1px solid #5A5655;    
      text-decoration : none; 
     
     }
    .Btn:hover{
      background : orange;
      color : #FFFFFF;
      border  : 1px solid orange; 
      text-decoration : none; 
    }
    .Text{ 
      border: 1px solid #E0E0E0; 
      width:25px;
      padding : 1px 5px 1px 5px;
    }  
    .Text:focus{ 
      border: 1px solid orange; 
    } 
    .scCart { 
    	padding: 10px 5px 5px 5px;
    	border: 1px solid #E0E0E0; 
    	width: 450px;
    	margin: 5px;
    	float:left;
      
    }
    .scProductList {
    	padding: 10px 5px 5px 5px;
    	border: 1px solid #E0E0E0;
    	width: 400px;
    	height:360px;
    	overflow:auto;
    	margin: 5px;
    	float:left;
     
    }
    .scCartList {
    	position: relative;
    	margin: 0;
    	padding: 1px;
    	background: #F8F8F8;
    	border: 1px solid #E0E0E0;
    	height: 250px;
    	overflow:auto;
    }
    .CartListHead {
    	padding: 0;
    	background: #F8F8F8;
    	border: 1px solid #E0E0E0; 
    	margin: 1px 0 1px 0;
    	height: 25px;
    	font-weight: bold; 
    }
    .scCartListItem {
    	position: relative;
    	margin-left: 0;
    	padding-left: 0;
    	list-style: none;
    	background: #F8F8F8;
    	border: 1px solid #E0E0E0; 
    	margin: 1px 0 0 0;
    	line-height: 1em;
    }
    .scCartListItem:hover {
    	background-color: #e5e5e5;
    }
    .scProductListItem {
      width:auto;
      margin:1px;
      background:#F8F8F8;
      overflow:show;
      padding:0;   /*12px 0px 2px 5px;*/    
      color:#0464BB;
      text-align:left;
      border:#E0E0E0 solid 1px;      
      
    }
    .scProductSelect {
    	display: none;
    	visibility:hidden;
    }
    .scULList {
    	margin: 0.25em 0 1em 0; 
    	position: relative;
    	display: block;
    	padding-left: 0; 
    	list-style: none; 
    }
    .scListItemLabel {
    	padding: 5px; 
    	display: block;
    }
    .scListItemRemove {
    	position: absolute;
    	right: 0; 
    	top: 6px; 
      background: #5A5655;
      color: #FFFFFF;
      margin : 0;
      padding : 1px 5px 2px 5px;
      text-align : center;
      border: 1px solid #5A5655;    
      text-decoration: none; 
     
    }
    .scListItemRemove:hover{
      background      : orange;
      color           : #FFFFFF;
      border          : 1px solid orange; 
      text-decoration : none; 
    }
    
    Code (markup):
    this is my results.php
    
    <!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>
    <title> JavaScript jQuery plugin</title>
    <link rel="stylesheet" type="text/css" href="css/style_smartcart.css" />
    </head>
    <body>
      <center>   
        <h2>Selected Products</h2>
      </center>
    <div id="sc_cart" style="width:950px;" class="scContainer"> 
    <?php
    // creating product array
    $product_array = array("100" =>array('product_id'=>'100', 'product_name'=>'Apple IPhone 3G', 'product_price'=>'1450.75', 'product_img'=>'images/product0.jpg'),
                           "101" =>array('product_id'=>'101', 'product_name'=>'Ice Pot', 'product_price'=>'10.25', 'product_img'=>'images/product1.jpg'),
                           "102" =>array('product_id'=>'102', 'product_name'=>'Style Stand', 'product_price'=>'6.15', 'product_img'=>'images/product2.jpg'),
                           "103" =>array('product_id'=>'103', 'product_name'=>'Coffee Maker', 'product_price'=>'120.35', 'product_img'=>'images/product3.jpg'));
     // get the selected product array
    // here we get the selected product_id/quantity combination asa an array
    $product_list = $_REQUEST['product_list'];
    if(!empty($product_list)) 
    {
    ?>
             <div class="scCartListHead">
                <table width='100%'><tr>
                   <td>&nbsp;&nbsp;Product</td>
                    <td width='80px'>Quantity</td>
                    <td width='130px'>Amount($)</td>
                    </tr></table>
             </div>
    <?php  
        $sub_total = 0;
        foreach($product_list as $product){
          $chunks = explode('|',$product);
          $product_id = $chunks[0];
          $product_qty = $chunks[1];
          $product_name = $product_array[$product_id]['product_name'];
          $product_amount = $product_array[$product_id]['product_price']*$product_qty;
          // calculate the subtotal
          $sub_total = $sub_total + $product_amount;
         // echo "Product Id: ".$product_id." Quantity: ".$product_qty."<br>";
    ?>
            <div class="scCartListHead">
               <table width='100%'><tr>
                 <td>&nbsp;&nbsp;<?php echo $product_name; ?></td>
                 <td width='80px'><?php echo $product_qty; ?></td>
                 <td width='130px'><?php echo $product_amount; ?></td>
                </tr></table>
           </div>
    <?php
        }
    ?>
            <div class="scCartListHead">
                <table width='100%'><tr>
                    <td>
                      <!-- Message Label -->
                       <span id="sc_message"></span></td>
                       <td width='100px'>Subtotal ($):</td>
                       <td width='120px'> 
                       <!-- Sub Total Label -->
                       <span id="sc_subtotal"><?php echo $sub_total; ?></span>
                       </td>
                       </tr></table>
                	 </div>
                   <br>
                   <form action="index.php" method="post">
                   <?php
                        // set the request for continue shopping
                        if(isset($product_list)){
                          foreach($product_list as $p_list){
                            $prod_options .='<input type="hidden" name="product_list[]" value="'.$p_list.'">';
                          }
                          echo $prod_options;
                        }
                   ?>
                	   <input style="width:200px;height:35px;float:left;" type="submit" class="scBtn" value="Continue Shopping">
                	 </form>     
    <?php    
    } 
    else 
    {	
    echo "<strong>Your Cart is Empty</strong>";
    }
    ?>
    </div>
    </body>
    </html>
    
    Code (markup):
    kindly tellme why it is not executing
     
    ravi951, Sep 6, 2011 IP