0
<div class='col'>
    <h5 class='text-right' id='gtotal'>
    </h5>
</div>
    <script>
    var gt=0; 
    var iprice=document.getElementsByClassName('iprice');
    var iquantity=document.getElementsByClassName('iquantity');
    var itotal=document.getElementsByClassName('itotal');
    var gtotal=document.getElementById('gtotal');

    function subTotal()
    {
        gt=0;
        for(i=0;i<iprice.length;i++)
        {
            itotal[i].innerText=(iprice[i].value)*(iquantity[i].value); 
            gt=gt+(iprice[i].value)*(iquantity[i].value);
        }
        gtotal.innerText=gt;
    }
    subTotal(); 
</script>

now i want to get this value of gtotal wihch generated by javascript in h5 id=gtotal how can i retrieve it in php code for run a query and insert in database. here is my php data base insertion code

<?php
session_start();
if($_SERVER["REQUEST_METHOD"]=="POST")
{
    if(isset($_POST['purchase']))
    {
        include "partials/_conn.php";
        $query1 = "INSERT INTO `order_manager`(`customer_name`) VALUES ('$_POST[name]')";
            if(mysqli_query($conn,$query1))
            {
                $order_id=mysqli_insert_id($conn);
                $query2="INSERT INTO `order_place`(`order_id`, `item_name`, `price`, `quantity`) VALUES (?,?,?,?)";
                $stmt=mysqli_prepare($conn,$query2);
                if($stmt)
                {
                    mysqli_stmt_bind_param($stmt,"isii",$order_id,$item_name,$price,$quantity);
                    foreach($_SESSION['cart'] as $key =>$values)
                    {
                        $item_name=$values['title'];
                        $price=$values['price'];
                        $quantity=$values['Quantity'];
                        $stmt->execute();
                    }
                    unset($_SESSION['cart']);
                    echo
                    "
                        <script>
                            alert('Order placed.');
                            window.location.href='sales1.php';
                        </script>
                    ";
                }
                else
                {
                    echo
                    "
                        <script>
                            alert('Query prepare error.');
                            window.location.href='sales1.php';
                        </script>
                    ";
                }
            }
            else
            {
                echo
                "
                    <script>
                        alert('Query not executed.');
                        window.location.href='sales1.php';
                    </script>
                ";
            }
    }
}
?>

here i want to recieve gtotal value and insert with customer name in database. check the code and suggest the best and clear answer.

0 Answers0