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
https://forums.phpfreaks.com/topic/217480-mysql_num_rows-error/
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);

?>

 

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);

 

I tried that before but it gave me:

 

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

 

You tried this???

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

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.

 

 

@shawn

 

$m = mysql_affected_rows($res);

 

int mysql_affected_rows ([ resource $link_identifier ] )

  ;)

 

Doh!!!

 

$q = "DELETE FROM `stocklist` WHERE `Stock Number`='".$rec."'"; 
$res = mysql_query($q, $link) or die(mysql_error());
$m = mysql_affected_rows($link)

;

Archived

This topic is now archived and is closed to further replies.

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