jakebur01 Posted March 13, 2008 Share Posted March 13, 2008 I am having trouble finding out where my problem is. One of these queries is returning false. How do I find out which one it is? function insert_order($order_details) { // extract order_details out as variables extract($order_details); // set shipping address same as address if(!$ship_name&&!$ship_address&&!$ship_city&&!$ship_state&&!$ship_zip&&!$ship_country) { $ship_name = $name; $ship_address = $address; $ship_city = $city; $ship_state = $state; $ship_zip = $zip; $ship_country = $country; } $conn = db_connect(); // insert customer address $query = "select customerid from customers where name = '$name' and address = '$address' and city = '$city' and state = '$state' and zip = '$zip' and country = '$country'"; $result = $conn->query($query); if($result->num_rows>0) { $customer = $result->fetch_object(); $customerid = $customer->customerid; } else { $query = "insert into customers values ('0', '$name','$address','$city','$state','$zip','$country')"; $result = $conn->query($query); if (!$result) return false; } $customerid = $conn->insert_id; $date = date('Y-m-d'); $query = "insert into orders values ('0', $customerid, ".$_SESSION['total_price'].", '$date', 'PARTIAL', '$ship_name', '$ship_address','$ship_city','$ship_state','$ship_zip', '$ship_country', '0', '0', '0', '0', '0', '0', '0','0','0','0','0','0','0','0')"; $result = $conn->query($query); if (!$result) return false; $query = "select orderid from orders where customerid = $customerid and amount > ".$_SESSION['total_price']."-.001 and amount < ".$_SESSION['total_price']."+.001 and date = '$date' and order_status = 'PARTIAL' and ship_name = '$ship_name' and ship_address = '$ship_address' and ship_city = '$ship_city' and ship_state = '$ship_state' and ship_zip = '$ship_zip' and ship_country = '$ship_country'"; $result = $conn->query($query); if($result->num_rows>0) { $order = $result->fetch_object(); $orderid = $order->orderid; } else return false; $_SESSION['ordernumber'] = $orderid; // insert each book foreach($_SESSION['cart'] as $isbn => $quantity) { $detail = get_book_details($isbn); $query = "delete from order_items where orderid = '$orderid' and isbn = '$isbn'"; $result = $conn->query($query); $query = "insert into order_items values ('$orderid', '$isbn', ".$detail['price'].", $quantity)"; $result = $conn->query($query); if(!$result) return false; } return $orderid; } Quote Link to comment https://forums.phpfreaks.com/topic/96049-finding-error/ Share on other sites More sharing options...
BlueSkyIS Posted March 13, 2008 Share Posted March 13, 2008 change each of these as shown: if (!$result) { echo "query failed: $query"); return false; } Quote Link to comment https://forums.phpfreaks.com/topic/96049-finding-error/#findComment-491726 Share on other sites More sharing options...
jakebur01 Posted March 13, 2008 Author Share Posted March 13, 2008 PHP Parse error: syntax error, unexpected ')', expecting ',' or ';' in Quote Link to comment https://forums.phpfreaks.com/topic/96049-finding-error/#findComment-491736 Share on other sites More sharing options...
jakebur01 Posted March 13, 2008 Author Share Posted March 13, 2008 query failed: insert into order_items values ('243', '753-04376', 223.99, 1)Could not store data, please try again. Quote Link to comment https://forums.phpfreaks.com/topic/96049-finding-error/#findComment-491738 Share on other sites More sharing options...
jakebur01 Posted March 14, 2008 Author Share Posted March 14, 2008 query failed: insert into order_items values ('243', '753-04376', 223.99, 1)Could not store data, please try again. Here is the code for this: What could be causing my error? $query = "insert into order_items values ('$orderid', '$isbn', ".$detail['price'].", $quantity)"; $result = $conn->query($query); Quote Link to comment https://forums.phpfreaks.com/topic/96049-finding-error/#findComment-491850 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.