0

Hello,

I am trying to update or delete item from cart but it;s not oking

    session_start();
    include("includes/layout/header.php");
    include_once("includes/connection.php");
    function get_product_name($pid){

        global $connection;
        $result=mysqli_query($connection, "select product_name from products where prod_id=$pid");
        $row=mysqli_fetch_array($result);
        return $row['product_name'];
    }

    function get_price($pid){
    global $connection;
        $result=mysqli_query($connection, "select product_price from products where prod_id=$pid");
        $row=mysqli_fetch_array($result);
        return $row['product_price'];
    }
    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;
    }
?>
<script language="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>    

Code for cart

<form name="form1" method="post">
            <div id="cart">
            <div class="cart-items">
                                                <table class="styled-table">
                                                    <thead>
                                                        <tr>
                                                            <th class="col_product text-left">Product</th>
                                                            <th class="col_remove text-right">&nbsp;</th>
                                                            <th class="col_qty text-right">Qty</th>
                                                            <th class="col_single text-right">Single</th>                                                         
                                                            <th class="col_total text-right">Total</th>
                                                        </tr>
                                                    </thead>
                                                    <?php
if(is_array($_SESSION['cart'])){
$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;
            ?>
                                                    <tbody>                                  

                                                        <tr>
                                                            <td class="col_product text-left">
                                                                <div class="image visible-desktop">
                                                                    <span class="single-price"><?=get_product_name($pid)?></span>
                                                                </div>
                                                            </td>

                                                            <td class="col_remove text-right">
                                                                <a href="javascript:del(<?=$pid?>)">Remove</a>
                                                                    <i class="icon-trash icon-large"></i>
                                                                </a>
                                                            </td>

                                                            <td class="col_qty text-right">
                                                                <input type="text" name="product<?=$pid?>" value="<?=$q?>" maxlength="3" size="2" >
                                                            </td>

                                                            <td class="col_single text-right">
                                                                <span class="single-price">$<?=get_price($pid)?></span>
                                                            </td>
<?php

}
?>
                                                            <td class="col_total text-right">
                                                                <span class="total-price">$<?=get_order_total()?></span>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </div>
            </div>

            <div class="box-footer">
                            <div class="pull-left">
                                <input type="button" class="btn btn-small" value="Continue Shopping" onclick="window.location='index.php'" />        
                            </div>

                            <div class="pull-right">
                                   <input type="button" value="Update Cart" onclick="update_cart()" class="btn btn-small mm20">

                                    <input type="button" value="Place Order" class="btn btn-primary btn-small mm20" onclick="window.location='billing.php'">

                                    </form>
                            </div>
                        </div>
2
Contributors
3
Replies
19
Views
2 Years
Discussion Span
Last Post by minitauros
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.