PHP / MySQL : How to INSERT into databse using WHILE loop : <p>I want to insert data from input form and at the same time from another table (shopping_cart) in one table (order). </p>

<p>I found that there is no problem with passing value from input form or select it from shopping cart, since I print all the value that I want to use to insert in table (order) and it displayed.</p>

<p>But, when execute a query to insert into table order, the output is fail and nothing insert in database.</p>

<p>Below is my code :</p>

<pre><code>&lt;?php
include('dbconnection.php');

$query1 = mysql_query("SELECT * FROM shopping_cart");

$bil = 1;   

while ($data = mysql_fetch_array($query1)) {

    //FROM TABLE SHOPPING_CART
    $item_name=$data['ITEM_NAME'];
    $cart_price=$data['CART_PRICE'];
    $cart_quantity=$data['CART_QUANTITY'];

    //FROM HTML FORM
    $total_price = $_POST['ORDER_TOTALPRICE'];
    $fullname = mysql_real_escape_string($_POST['FULLNAME']);
    $address = mysql_real_escape_string($_POST['ADDRESS']);
    $phone = mysql_real_escape_string($_POST['PHONE']);

    echo $item_name;
    echo $cart_price;
    echo $cart_quantity;
    echo $fullname;
    echo $address;
    echo $phone;
    echo $total_price;

    //SOMETHING WRONG HERE ?
    $query = mysql_query("INSERT INTO order (ORDER_TOTALPRICE, ITEM_NAME, 
    CART_PRICE, CART_QUANTITY, FULLNAME, ADDRESS, PHONE) VALUES ('$total_price','$item_name','$cart_price','$cart_quantity','$fullname','$address','$phone')");

    if ($query){
        echo "success";
    }
    else{
        echo "fail";


    }
    $bil++;

}

?&gt;
</code></pre>
