hi, im having a few problems with the order being added to my db. the information from the checkou form is being stored in the varibles, but it cannot add the order to the database. please help me ive been strglling for ages. thanks
function insert_order($order_details)
{
// extract order_details out as variables
extract($order_details);
$conn = db_connect();
$date = date('Y-m-d');
$query = "insert into orders values
('', ".$_SESSION['$valid_user'].", ".$_SESSION['total_price'].", '$date', 'PARTIAL', '$sname',
'$saddress','$scity','$spost')";
$result = $conn->query($query);
if (!$result)
return false;
$query = "select orderid from orders where
customerid = ".$_SESSION['$valid_user']." and
amount > ".$_SESSION['total_price']."-.001 and
amount < ".$_SESSION['total_price']."+.001 and
date = '$date' and
order_status = 'PARTIAL' and
ship_name = '$sname' and
ship_address = '$saddress' and
ship_city = '$scity' and
ship_post = '$spost'";
$result = $conn->query($query);
if($result->num_rows>0)
{
$order = $result->fetch_object();
$orderid = $order->orderid;
}
else
return false;
// insert each dvd
foreach($_SESSION['cart'] as $dvd_no => $quantity)
{
$detail = get_dvd_details($dvd_no);
$query = "delete from order_items where
orderid = '$orderid' and dvd_no = '$dvd_no'";
$result = $conn->query($query);
$query = "insert into order_items values
('$orderid', '$dvd_no', ".$detail['price'].", $quantity)";
$result = $conn->query($query);
if(!$result)
return false;
}
return $orderid;
}
session_start();
do_html_header("Checkout");
// create short variable names
$sname = $_POST['sname'];
$saddress = $_POST['saddress'];
$scity = $_POST['scity'];
$spost = $_POST['spost'];
// if filled out
if($_SESSION['cart']&&$sname&&$saddress&&$scity&&$spost)
{
// able to insert into database
if( insert_order($_POST)!=false )
{
//display cart, not allowing changes and without pictures
display_cart($_SESSION['cart'], false, 0);
display_shipping(calculate_shipping_cost());
//get credit card details
display_card_form($name);
display_button('show_cart.php', 'continue-shopping', 'Continue Shopping');
}
else
{
echo $_SESSION['valid_user'];
echo
echo 'Could not store data, please try again.';
display_button('checkout.php', 'back', 'Back');
}
}
else
{
echo 'You did not fill in all the fields, please try again.<hr />';
display_button('checkout.php', 'back', 'Back');
}
do_html_footer();