otuatail Posted May 25, 2014 Share Posted May 25, 2014 $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 Quote Link to comment Share on other sites More sharing options...
Barand Posted May 25, 2014 Share Posted May 25, 2014 See what mysql_error() has to say about it. Quote Link to comment Share on other sites More sharing options...
Frank_b Posted May 25, 2014 Share Posted May 25, 2014 $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'); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.