Jump to content

= mysql_num_rows


otuatail

Recommended Posts

$sql = "SELECT current FROM LIBusersX WHERE UserKey = '$Key' AND K_Type = $type AND current > 0 ";
	// echo $sql . "<br>";
	$query = mysql_query ($sql) or die ("E112-100A");
	$total = mysql_num_rows($query) or die ("E112-101A");

Hi

I have a website with a few users. I set up a system so that some users (as a trial) can only log on a fixed number of times. I have a field called current that counts down to zero. However when it reaches zero I get my error E112-101A

 

Why do I get an error? Surely I should just get $total = 0

 

 

 

Link to comment
Share on other sites

$total = mysql_num_rows($query) or die ("E112-101A");

that is unlogic. The keyword or takes a role in a logic expression. Think about 

if(mysql_num_rows($query) or die ("E112-101A"))
    ...

if the first part of the expression (before the or) gives a TRUE than the expression will stop. But if the first part gives FALSE the expression will continue with the second part after the as which does stop your script with die(). For the case that you might not know it, FALSE equals to 0 (zero) and all other values equals to TRUE.

 

in more helpfull words i could say that mysql_num_rows() and the combination 'or die()' is a very bad combination.You should alway check php.net for what values could be returned by the function you use, in this case the mysql_num_rows() function. Just take a look under the "Return Values" chapter here: http://www.php.net/manual/en/function.mysql-num-rows.php. you will learn that any value from of zero can be returned or FALSE on failures. 

 

Now comes a little bit hard to understand part of PHP. PHP can distinguish a FALSE from a 0 but you should use a special === or !== operator.

$rows = mysql_num_rows($query);
if($rows === FALSE)
   die('E112-101A');
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.