Jump to content

Failed query


Lassie

Recommended Posts

I am having trouble establishing what is wrong with an insert query within a function used to update oder details within a simple cart application. Can any one suggest how I can debug this or see my error.
The first query updates successfully and the variables are all present.
The code 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;
  }

    include("misc.inc");
    $connection = mysql_connect($host,$user,$password)   
      or die ("$connection:".mysql_error($connection));
  $db = mysql_select_db($database,$connection)         
      or die ("$db:".mysql_error($connection));
 
    $query = "insert into customer values
            ('', '$name','$address','$city','$state','$zip','$country')";
    $result = mysql_query($query);
   

if (!$result)
    return false;
 
  $customer_id = mysql_insert_id();
  echo "$customer_id";
 
  /* Insert Customer Order details */
  $order_date = date('Y-m-d');
 
 

  $query = "INSERT INTO order (total,customer_id,order_date,ship_name,ship_address,ship_city,ship_state,ship_zip, ship_country,order_status) VALUES
(".$_SESSION['total_price'].",'$customer_id','$order_date','$ship_name','$ship_address','$ship_city',
'$ship_state','$ship_zip','$ship_country','PARTIAL')";



$result = mysql_query($query);

if (!$result)
return false;
 
  /* Retrieve Order No */

  $query = "select order_number from order where
               
              total > ".$_SESSION['total_price']."-.001 and
              total < ".$_SESSION['total_price']."+.001 and
              order_date = '$order_date' 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'and
  order_status = 'PARTIAL'";
  $result = mysql_query($query);
 
  $num_ord = mysql_num_rows($result);
 
  if ($num_ord>0)
 
  {
    $result = mysql_fetch_row($result);
    $order_number = $result;
   
}
  else
  return false;
 
 
  // insert each book
  foreach($_SESSION['cart'] as $product_id => $quantity)
  {
    $detail = get_book_details($product_id);
   
    $query = "INSERT INTO order_contents (product_id, quantity,price) VALUES
              ($product_id,$quantity,".$detail['price'].")";
    $result = mysql_query($query);

 
    if(!$result)
   
      return false;
  }

  return $order_number;

}

The table structure is

  Field  Type  Attributes  Null  Default  Extra  Action
order_number  int(6)   No    auto_increment  Change Drop Primary Index Unique Fulltext
customer_id  int(5)   No  0    Change Drop Primary Index Unique Fulltext
total  float(6,2)   No  0.00    Change Drop Primary Index Unique Fulltext
order_date  date   No  0000-00-00    Change Drop Primary Index Unique Fulltext
ship_name  varchar(50)   No      Change Drop Primary Index Unique Fulltext
ship_address  varchar(50)   No      Change Drop Primary Index Unique Fulltext
ship_city  varchar(50)   No      Change Drop Primary Index Unique Fulltext
ship_state  varchar(30)   No      Change Drop Primary Index Unique Fulltext
ship_zip  varchar(10)   No      Change Drop Primary Index Unique Fulltext
ship_country  varchar(30)   No      Change Drop Primary Index Unique Fulltext
order_status  varchar(10)   No      Change Drop Primary Index Unique Fulltext
With selected: Check All  /  Uncheck All    With selected:  Change Drop Primary Index Unique Fulltext
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.