Hi guys I have a problem with a script I am getting a Warning message:
Warning: Supplied argument is not a valid MySQL result resource in order_fns.php on line 38
Could not store data, please try again.
The code I am using is -
11function insert_order($order_details)
12{
13 global $total_price;
14 global $cart;
15 //extract order_details out as variables
16 extract($order_details);
17
18
19 //set shipping address same as address
20 if(!$ship_name&&!$ship_1st_add&&!$ship_2nd_add&&!$ship_city&&!$ship_state&&!$ship_zip&&!$ship_country)
21 {
22 $ship_name = $name;
23 $ship_1st_add = $first_add;
24 $ship_2nd_add = $second_add;
25 $ship_city = $city;
26 $ship_state = $state;
27 $ship_zip = $zip;
28 $ship_country = $country;
29 }
30
31 $conn = db_connect();
32
33 //insert customer address
34 $query = "select customerid from contact where
35 name = '$name' and 1st_add = '$first_add' and 2nd_add = '$second_add' and town = '$city' and state = '$state'
36 and zip = '$zip' and country = '$country'";
37 $result = mysql_query($query);
38 if(mysql_num_rows($result)>0)
39 {
40 $customer_id = mysql_result($result, 0, "customerid"
41 }
42 else
43 {
44 $query = "insert into contact values(
45'', '$first_add', '$second_add','$city','$zip', '$email', '$fax', '$name', '$country', '$state', '$tel' )";
$result = mysql_query($query);
if (!$result)
return false;
}
$query = "select customerid from contact where
name = '$name' and 1st_add = '$first_add'
and 2nd_add = '$second_add' and town = '$city' and state = '$state'
and zip = '$zip' and country = '$country'";
$result = mysql_query($query);
if(mysql_numrows($result)>0)
{
$customerid = mysql_result($result, 0, "customerid"
}
else
{
return false;
}
$date = date("Y-m-d"
$query = "insert into orders values
('', $customerid, $total_price, '$date', 'PARTIAL', '$ship_name',
'$ship_1st_add','$ship_2nd_add', '$ship_city','$ship_state','$ship_zip',
'$ship_country')";
$result = mysql_query($query);
if (!$result)
return false;
$query = "select orderid from orders where
customerid = $customerid and
amount > $total_price-.001 and
amount < $total_price+.001 and
date = '$date' and
order_status = 'PARTIAL' and
ship_name = '$ship_name' and
ship_1st_add = '$ship_1st_add' and
ship_2nd_add = '$ship_2nd_add' and
ship_city = '$ship_city' and
ship_state = '$ship_state' and
ship_zip = '$ship_zip' and
ship_country = '$ship_country'";
$result = mysql_query($query);
if(mysql_numrows($result)>0)
$orderid = mysql_result($result, 0, "orderid"
else
return false;
// insert each product
foreach($cart as $productID => $quantity)
{
$detail = get_product_details($productId);
$query = "delete from order_items where
orderid = '$orderid' and productId = '$productId'";
$result = mysql_query($query);
$query = "insert into order_items values
('$orderid', '$productID', ".$detail["price"].", $quantity)";
$result = mysql_query($query);
if(!$result)
return false;
}
return $orderid;
}
?>
Any ideas?
Warning: Supplied argument is not a valid MySQL result resource in order_fns.php on line 38
Could not store data, please try again.
The code I am using is -
11function insert_order($order_details)
12{
13 global $total_price;
14 global $cart;
15 //extract order_details out as variables
16 extract($order_details);
17
18
19 //set shipping address same as address
20 if(!$ship_name&&!$ship_1st_add&&!$ship_2nd_add&&!$ship_city&&!$ship_state&&!$ship_zip&&!$ship_country)
21 {
22 $ship_name = $name;
23 $ship_1st_add = $first_add;
24 $ship_2nd_add = $second_add;
25 $ship_city = $city;
26 $ship_state = $state;
27 $ship_zip = $zip;
28 $ship_country = $country;
29 }
30
31 $conn = db_connect();
32
33 //insert customer address
34 $query = "select customerid from contact where
35 name = '$name' and 1st_add = '$first_add' and 2nd_add = '$second_add' and town = '$city' and state = '$state'
36 and zip = '$zip' and country = '$country'";
37 $result = mysql_query($query);
38 if(mysql_num_rows($result)>0)
39 {
40 $customer_id = mysql_result($result, 0, "customerid"
41 }
42 else
43 {
44 $query = "insert into contact values(
45'', '$first_add', '$second_add','$city','$zip', '$email', '$fax', '$name', '$country', '$state', '$tel' )";
$result = mysql_query($query);
if (!$result)
return false;
}
$query = "select customerid from contact where
name = '$name' and 1st_add = '$first_add'
and 2nd_add = '$second_add' and town = '$city' and state = '$state'
and zip = '$zip' and country = '$country'";
$result = mysql_query($query);
if(mysql_numrows($result)>0)
{
$customerid = mysql_result($result, 0, "customerid"
}
else
{
return false;
}
$date = date("Y-m-d"
$query = "insert into orders values
('', $customerid, $total_price, '$date', 'PARTIAL', '$ship_name',
'$ship_1st_add','$ship_2nd_add', '$ship_city','$ship_state','$ship_zip',
'$ship_country')";
$result = mysql_query($query);
if (!$result)
return false;
$query = "select orderid from orders where
customerid = $customerid and
amount > $total_price-.001 and
amount < $total_price+.001 and
date = '$date' and
order_status = 'PARTIAL' and
ship_name = '$ship_name' and
ship_1st_add = '$ship_1st_add' and
ship_2nd_add = '$ship_2nd_add' and
ship_city = '$ship_city' and
ship_state = '$ship_state' and
ship_zip = '$ship_zip' and
ship_country = '$ship_country'";
$result = mysql_query($query);
if(mysql_numrows($result)>0)
$orderid = mysql_result($result, 0, "orderid"
else
return false;
// insert each product
foreach($cart as $productID => $quantity)
{
$detail = get_product_details($productId);
$query = "delete from order_items where
orderid = '$orderid' and productId = '$productId'";
$result = mysql_query($query);
$query = "insert into order_items values
('$orderid', '$productID', ".$detail["price"].", $quantity)";
$result = mysql_query($query);
if(!$result)
return false;
}
return $orderid;
}
?>
Any ideas?