Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL error

Status
Not open for further replies.

boab

Programmer
May 30, 2001
75
GB
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'&quot;;
$result = mysql_query($query);
if(mysql_numrows($result)>0)
$orderid = mysql_result($result, 0, &quot;orderid&quot;);
else
return false;


// insert each product
foreach($cart as $productID => $quantity)
{
$detail = get_product_details($productId);
$query = &quot;delete from order_items where
orderid = '$orderid' and productId = '$productId'&quot;;
$result = mysql_query($query);
$query = &quot;insert into order_items values
('$orderid', '$productID', &quot;.$detail[&quot;price&quot;].&quot;, $quantity)&quot;;
$result = mysql_query($query);
if(!$result)
return false;
}

return $orderid;
}

?>
Any ideas?
 
Try echoing out $query. My bet is that its not line 38 that is the problem. Some editors wrap thew line, thus giving a false sense of line numbers. It may be you need to concatinate the string, i.e;

$query = &quot;SELECT customerid FROM contact WHERE name = '&quot; . $name . &quot;' AND 1st_add = '&quot; . $first_add . &quot;' and 2nd_add = etc....

You see what I mean? My betting is that you are passing along a query something like;

$query = &quot;select customerid from contact where name = '' and 1st_add = '' and 2nd_add = '' and town = '' and state = '' and zip = '' and country = ''&quot;;

;)

Give it a go...could be right :D

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top