"Insert Into" statement won't update sql table
Posted: Wed Jun 15, 2005 1:21 pm
I have a php script that gets the information from an order form, and puts the information into 3 different tables. The first table is the "payment" table, the second is the "orders" table, and the third is the "line_item" table. The information is entered into the first and third tables correctly, but no data is entered into the second table. The code is exactly the same for the first and second tables, however the second table, "orders" gets no data inserted into it. I have included the code below, so you can see what I'm doing. The problem is in the //insert order information. I have tried using the code 2 ways, as you will see in the //original insert order information. Neither way writes to the "orders" table in the Database. However, the "payments" table and the "line_item" tables are being updated correctly.
Anyone have any ideas?
Thanks.
Code: Select all
function process_order()
{
// Get order form variables
$comments = $_REQUEST['comments'];
$order_total = $_REQUEST['order_total'];
$card_type = $_REQUEST['card_type'];
$card_name = $_REQUEST['card_name'];
$card_number = $_REQUEST['card_number'];
$card_expiration_date = $_REQUEST['card_expiration_date'];
$card_ccv_number = $_REQUEST['card_ccv_number'];
$username = $_SESSION['username'];
$sql = "SELECT customer_id FROM customer_name WHERE username = '".$username."'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$customer_id = $row['customer_id'];
$order_time = date('Y-m-d h:i a');
$check_order_time = $order_time;
$order_string = $_SESSION['lineItems_in_cart'];
if($order_string != '')
{
// Connect to DB
$db = new DATABASE;
$db->db('connect');
// insert payment information
$result = mysql_query("INSERT INTO `payment`
(customer_id, payment_type, payment_amount, card_type, card_name, card_number, card_expiration, card_ccv_number, date)
VALUES
(\"$customer_id\", 'cc', \"$order_total\", \"$card_type\", \"$card_name\", \"$card_number\",
\"$card_expiration_date\", \"$card_ccv_number\", \"$order_time\")");
$payment_id = mysql_insert_id();
// Get cart weight
$total_weight = $this->get_cart_weight();
// insert order information
$result = mysql_query("INSERT INTO `orders`
(customer_id, payment_id, order_string, order_total, order_weight, order_status, comments, date)
VALUES
(\"$customer_id\", \"$payment_id\", \"$order_string\", \"$order_total\", \"$total_weight\", 'Pending',
\"$comments\", \"$order_time\")");
$order_id = mysql_insert_id();
//original insert order line
//$sql = "INSERT INTO `orders`
//(customer_id, payment_id, order_string, order_total, order_weight, order_status, comments, date)
//VALUES
//(\"$customer_id\", \"$payment_id\", \"$order_string\", \"$order_total\", \"$total_weight\", 'Pending',
//\"$comments\", \"$order_time\")";
//$result = mysql_query($sql);
//$order_id = mysql_insert_id();
$cart_lineItems = $this->get_cart();
$cart_lineItem_count = count($cart_lineItems);
$i = 0;
$lineItem_id = 1;
while ($i < $cart_lineItem_count)
{
$lineitems = explode("~", $cart_lineItems[$i]);
$product_id = $lineitems[0];
$quantity = $lineitems[1];
$ship_to = $lineitems[2];
$sql = "INSERT INTO `line_item`
(lineitem_id, order_id, product_id, ship_to, customer_id, quantity)
VALUES
(\"$lineitem_id\", \"$order_id\", \"$product_id\", \"$ship_to\", \"$customer_id\",
\"$quantity\")";
$result = mysql_query($sql);
//echo "sql: ".$sql."<br>";
$lineItem_id++;
$i++;
}
//exit;
// Unload the cart
unset($_SESSION['lineItems_in_cart']);
//print $orderinfo;
print "<p CLASS=\"clsP\">Thank you for submitting your order. Feel free to continue to use the site, just remember to <A HREF='index.php?page=logout' >Logout</A> when you are finished!</p>";
}
else
{
print "<p CLASS=\"clsP\">There is nothing in your cart to process!</p>";
}
}Thanks.