Jump to content

mysql_num_rows error??


mat3000000

Recommended Posts

Get an error saying:

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\admin\delete.php on line 16

Sorry, but we can not find an entry to match your query

 

Surely this means the code has worked because of the last line, but i can't get rid of the error! :(

 

$q = "DELETE FROM `stocklist` WHERE `Stock Number`='".$rec."'";

$res = mysql_query($q, $link)
or die (mysql_error());

$anymatches = mysql_num_rows($res); 
if ($anymatches == 0)
	die ('Sorry, but we can not find an entry to match your query<br><br>'); 

	echo '<h1>Entry has been deleted!</h1><br><br>';

mysql_close($link);

Link to comment
Share on other sites

OK, here is what I have now but the output is "Query Failure" Why???

 

$q = "DELETE FROM `stocklist` WHERE `Stock Number`='".$rec."'";

$m = mysql_affected_rows() or die (mysql_error()); 

//if not numerical must use '".$eg."'
$res = mysql_query($q, $link)
or die (mysql_error());

	if ($m < 0)
	echo ('Query Failure');

if ($m == 0)
	echo ('Sorry, but we can not find an entry to match your query<br><br>'); 

if ($m > 0)
		echo '<h1>Entry has been deleted!</h1><br><br>';

mysql_close($link);

?>

 

Link to comment
Share on other sites

Now there is no output at all????

$q = "DELETE FROM `stocklist` WHERE `Stock Number`='".$rec."'";

$res = mysql_query($q, $link);

$m = mysql_affected_rows() or die (mysql_error()); 

	if ($m < 0)
	echo ('Query Failure');

if ($m == 0)
	echo ('Sorry, but we can not find an entry to match your query<br><br>'); 

if ($m > 0)
		echo '<h1>Entry has been deleted!</h1><br><br>';

mysql_close($link);

 

Link to comment
Share on other sites

Your original code was better structured.  mysql_affected_rows() isn't a catchall error function, it will work when you actually execute a valid query.  Your original code checked that, but you've restructured things now, so that it's hard to tell what is going on.

 

How about going back to:

 

$q = "DELETE FROM `stocklist` WHERE `Stock Number`='".$rec."'";

$res = mysql_query($q, $link)
or die (mysql_error());

$anymatches = mysql_affected_rows($res); 
if ($anymatches == 0)
  die ('Sorry, but we can not find an entry to match your query

'); 

echo 'Entry has been deleted!

';
mysql_close($link);

 

In general, this points out a good practice to get into.

 

-When you're trying to get something to work, don't refactor at the same time.  Get the code working, THEN refactor.  You are busy attempting to do both things at the same time, which leads to confusion.

 

 

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.