Skor Posted November 11, 2007 Share Posted November 11, 2007 I'm receiving the error above in my shopping cart application. I sell one-off items and use Paypal as the payment engine. In the remote possibility an item was previously purchased I loop through each order and update one at a time. I'm counting rows so if a record is not updated, I'd like to know. Strangely, it's working as designed (sending emai), but don't want to deploy unless I know why this error is occuring. Here's what I've got so far. Here's the full error: 1. is not a valid MySQL result resource in cartworks15.php on line 105. 2. Do I need to change the variable to a different function. Is my syntax correct. Please let me know. Thanks in advance. 3. The code: mysql_query ($query); // breaks the string into an array of products $products = explode("~", $cart); $i = 0; // breaks each product string into its own array foreach($products as $var => $val){ $product[$i] = explode(":", $val); $desc = $product[$i][0]; $qty = $product[$i][1]; $money = $product[$i][2]; $pid = $product[$i][4]; $update = "UPDATE ckd_labinv SET status ='S', sold_code = 'COD', sold_date = NOW() WHERE pid = '$pid' and status = 'A'"; mysql_query($update) or die(mysql_error()); $i++; } //echo '...Updated Database <br>'; $to = "[email protected]"; $subject = "Already Purchased Alert!"; $contents = "\nThe following item has already been purchased:\n\n * $desc \n\nThis item was purchased by the following customer:\n\n $inv_name,$email, on $date.\n"; $from_header = "From: [email protected]"; $num_rows = mysql_num_rows($update); [color="Red"][b]//offending line[/b][/color] //mysql_affected_rows($update); if ($num_rows == 0) { mail( $to, $subject, $contents, $from_header); echo '...sent Already Purchased Alert <br>'; } Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/76825-warning-mysql_num_rows-supplied-argument-error/ Share on other sites More sharing options...
trq Posted November 11, 2007 Share Posted November 11, 2007 This is a common error when your query has failed and you have not checked your queries result. At the very least you should always use... mysql_query ($query) or die(mysql_error()); But (IMO) its best to use.... <?php if ($result = mysql_query($sql)) { // $result is safe to use. if (mysql_num_rows($result)) { // $result holds records. } else { // no records found. } } else { // query failed, handle error gracefully. } ?> Link to comment https://forums.phpfreaks.com/topic/76825-warning-mysql_num_rows-supplied-argument-error/#findComment-388957 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.