Jump to content

Warning: mysql_num_rows(): supplied argument Error


Skor

Recommended Posts

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.  :confused:  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 = "me@test.com";
$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: purchasealerts@ckd.com";
$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
Share on other sites

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
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.