INSERT weirdness

wxdqz

New Member
I have a problem where INSERT for mysql works sporadically. I have a section of code (see below) that inserts records into three different tables. Most of the time, one of these INSERTs doesn't go into the table.

The problem is that it is not the same INSERT each time (thus not a syntax problem).

I don't know if it's a MySQL issue or a PHP issue.

Any help/thoughts would be greatly appreciated!

***********************************


// HANDLE NEW LINEITEMS
$line_count = count($lineitem);
for ($n=0; $n<$line_count; $n++) {

echo "iteration: $n<br>";

// QUERY FROM cart_lineitems
$lineitem_old_query = "SELECT * FROM $this->table1 WHERE auto_id='$lineitem[$n]'";
$lineitem_old_result = MYSQL_QUERY($lineitem_old_query);
$lineitem_old = mysql_fetch_array($lineitem_old_result);


// COPY TO cart_ordereditems
$lineitem_new_query = "INSERT INTO $this->table2 (order_num, part_num, quantity, description, price, comments) VALUES('$order_num','".$lineitem_old["part_num"]."','".$lineitem_old["quantity"]."','".$lineitem_old["description"]."','".$lineitem_old["price"]."','".$lineitem_old["comments"]."')";
$lineitem_new_result = MYSQL_QUERY($lineitem_new_query);


// DELETE FROM cart_lineitems
$delete_old_query = "DELETE FROM $this->table1 WHERE auto_id='$lineitem[$n]'";
$delete_old_result = MYSQL_QUERY($delete_old_query);

}


// CREATE NEW ORDER IN cart_orders
$order_new_query = "INSERT INTO $this->table3 (order_num, cc_id) VALUES('$order_num','$PNREF')";
$order_new_result = MYSQL_QUERY($order_new_query);


// CREATE NEW CUSTOMER IN cart_customers
$cust_new_query = "INSERT INTO $this->table4 (cust_id, bill_name, bill_company, bill_email, bill_add1, bill_add2, bill_city, bill_state, bill_zip, bill_phone, ship_name, ship_company, ship_add1, ship_add2, ship_city, ship_state, ship_zip, ship_phone, card_type, card_number, card_name, card_month, card_year) VALUES('$PNREF','$bill_name','$bill_company','$bill_email','$bill_add1','$bill_add2','$bill_city','$bill_state','$bill_zip','$bill_phone','$ship_name','$ship_company','$ship_add1','$ship_add2','$ship_city','$ship_state','$ship_zip','$ship_phone','$card_type','$card_number','$card_name','$card_month','$card_year')";
$cust_new_result = MYSQL_QUERY($cust_new_query);
 
Back
Top