loop problem
Posted: Sun Mar 26, 2006 10:15 am
Hi there,
I am using a loop to try and add records of data from two tables to a single table. The problem is that my code only adds one record to the table.
What am i doing wrong?
I am using a loop to try and add records of data from two tables to a single table. The problem is that my code only adds one record to the table.
Code: Select all
<?php
include"conn.inc.php";
//SET ALL VARIABLES NEED TO STORE IN ORDER_TABLE--------------------------
$customerid = $_REQUEST['cid'];
$deliveryid = $_REQUEST['del'];
$sessid = $_REQUEST['sess'];
$today = date("d-m-Y");
//------------------------------------------------------------------------
//STORE ORDER AND GET ORDER NUMBER FROM ID
$insert_details = "INSERT INTO product_order (
order_date, customer_id)
VALUES (
'$today',
'$customerid')";
$insert_order = mysql_query($insert_details)
or (mysql_error());
//SET ORDER NUMBER
$orderid = mysql_insert_id();
//GET ORDER DETAILS FOR EACH ITEM ORDERED (order_qty and product_id)
$query = "SELECT * FROM carttemp WHERE carttemp_sess = '$sessid'";
$results = mysql_query($query)
or die(mysql_error());
while ($row = mysql_fetch_array($results)) {
extract($row);
$order_qty = $row['carttemp_quan'];
$productid = $row['carttemp_prodnum'];
//ADD EACH ITEM TO ORDER DETAILS TABLE------------------------------------
$insert4 = "INSERT INTO order_details (
order_num, order_date, order_qty, customer_id, product_id, del_id)
VALUES (
'$orderid',
'$today',
'$order_qty',
'$customerid',
'$productid',
'$deliveryid')";
$insert_details4 = mysql_query($insert4)
or (mysql_error());
}
?>