samoht Posted October 1, 2007 Share Posted October 1, 2007 <?php function saveOrder($CPC) { $orderId = 0; $shippingCost = 5; $requiredField = array('hidShippingFirstName', 'hidShippingLastName', 'hidShippingAddress1', 'hidShippingCity', 'hidShippingPostalCode', 'hidPaymentFirstName', 'hidPaymentLastName', 'hidPaymentAddress1', 'hidPaymentCity', 'hidPaymentPostalCode'); if (checkRequiredPost($requiredField)) { extract($_POST); // make sure the first character in the // customer and city name are properly upper cased $hidShippingFirstName = ucwords($hidShippingFirstName); $hidShippingLastName = ucwords($hidShippingLastName); $hidPaymentFirstName = ucwords($hidPaymentFirstName); $hidPaymentLastName = ucwords($hidPaymentLastName); $hidShippingCity = ucwords($hidShippingCity); $hidPaymentCity = ucwords($hidPaymentCity); //for clients with accounts. $ClientId =(int)($hidClientId); $ShipAddressId =(int)($hidShipAddressId); $BillAddressId =(int)($hidBillAddressId); $Email =($hidEmail); $cartContent = getCartContent($CPC); $numItem = count($cartContent); // save order & get order id $sql = "INSERT INTO `orders` ( `ClientId`, `ShipAddressId`, `BillAddressId`, `Email`, `OrderDate`, `OrderStatus`, `AssignedTo`, `DateAssigned`, `Location`, `FlagStatus`, `FlagStatus2`, `DateStatus`) VALUES ( '$ClientId', '$ShipAddressId', '$BillAddressId', '$Email', NOW(), 'New', NULL, NOW(), 'WS', 'N', NULL, NOW())"; $result = dbQuery($sql) or die('no good order info'); // get the order id $orderId = dbInsertId(); if ($orderId) { // save order items for ($i = 0; $i < $numItem; $i++) { $sql = "INSERT INTO orderitems(OrderId, ProductId, OrderQty) VALUES ($orderId, {$cartContent[$i]['ProductId']}, {$cartContent[$i]['qty']})"; $result = dbQuery($sql); } // update product stock for ($i = 0; $i < $numItem; $i++) { $sql = "UPDATE product SET QtyInStock = QtyInStock - {$cartContent[$i]['qty']} WHERE ProductId = {$cartContent[$i]['ProductId']}"; $result = dbQuery($sql); } // then remove the ordered items from cart for ($i = 0; $i < $numItem; $i++) { $sql = "DELETE FROM cart WHERE CartId = {$cartContent[$i]['CartId']}"; $result = dbQuery($sql); } } } return $orderId; } This function used to be working fine - but now I keep getting a $orderId of 0??? but when I insert the sql directly into phpMyAdmin - it updates the table just fine? - I have also tested each of my variables and they work fine. Any idea where I could be missing something? let me know if you need more code. Quote Link to comment https://forums.phpfreaks.com/topic/71411-solved-function-not-completing/ Share on other sites More sharing options...
BlueSkyIS Posted October 1, 2007 Share Posted October 1, 2007 need to see code for the functions used in the function posted. Quote Link to comment https://forums.phpfreaks.com/topic/71411-solved-function-not-completing/#findComment-359443 Share on other sites More sharing options...
samoht Posted October 1, 2007 Author Share Posted October 1, 2007 well I tracked down the problem. Thanks for the help anyway Quote Link to comment https://forums.phpfreaks.com/topic/71411-solved-function-not-completing/#findComment-359491 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.