Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Shopping Cart:Update Product Quantity using Session Variable

General discussions related to php

Moderators: macek, egami, gesf

Shopping Cart:Update Product Quantity using Session Variable

Postby absphp21 » Thu Jan 30, 2014 2:06 am

Hello,

I want to Update the Product Quantity using Session Variable. Can anyone help me with the code and how to go about it?

Here is the Code for the my_cart.php page

Code: Select all
            <tr>
            <th class="tablerow">Product Code</th>
            <th class="tablerow">Product Name</th>
            <th class="tablerow">Image</th>
            <th class="tablerow">Quantity</th>
            <th class="tablerow">Price</th>
            <th class="tablerow">Total Price</th>
            <th class="tablerow">Action</th>                 
            </tr>
       
            <?php
            $grand_total = 0;                           // For Calculating Grand Price
         foreach($_SESSION['cart'] as $id=>$quantity)
         {
            $sql="SELECT * FROM products WHERE id='$id'";
            $result=mysql_query($sql) or die("Error Message");
            while($row=mysql_fetch_array($result))
            {      
            $grand_total+= $row['product_price']*$quantity;   // For Calculating Grand Price   
            ?>       
       
           <tr>               
            <td class="tablerow"><?php echo $row['id']; ?></td>
            <td class="tablerow"><?php echo $row['product_name']; ?></td>
            <td class="tablerow"><?php echo "<img height='50' width='50' src='admin/".$row['product_image']."'/>" ?></td>
               
                <form name="update_cart" action="update_cart.php" method="post">
               
                <td class="tablerow"><input type="text" name="quantity" value="<?php echo $quantity; ?>" /><br /><input type="image" src="admin/images/updatecart.png" name="Update" value="Update" /></td>
               
                </form>
               
                <td class="tablerow"><?php echo $row['product_price']; ?></td>
            <td class="tablerow"><?php echo $quantity*$row['product_price']; ?> </td>
            <td class="tablerow"><?php print "<a href='delete_cart.php?pid=".$row['id']."'><img src='admin/images/delete.png'></a>"; ?></td></form>
            </tr>
         
         <?php
            }
         }
         ?>
           
          <tr>
            <td class="tablerow" colspan="7">Grand Total: Rs <?php echo $grand_total; ?></td>
            </tr>      
           
          <tr>
            <td class="tablerow" colspan="7"><?php print "<a href='clear_cart.php'><img src='admin/images/clearcart.png'></a><a href='http://localhost/Shopping-Cart/front-end/'><img src='admin/images/continueshopping.png'></a><a href='update_cart.php'><img src='admin/images/placeorder.png'></a>";?></td>
            </tr>             

         </table>
absphp21
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Jan 30, 2014 1:49 am

Return to PHP General

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.