Jump to content


somethings wrong with the mysql_num_rows(

  • Please log in to reply
2 replies to this topic

#1 OranniS

  • New Members
  • Pip
  • Newbie
  • 6 posts
  • LocationGent, Belgium

Posted 24 September 2006 - 02:04 AM

i was making a start page, where one must register a personal code, as in password, to proceed to the main site.

to check if the code has already been used by someone else, i used the mysql_num_rows() function, but somethings making it fail...

this is where i define a function wich is causing the whole jam. ive tried echoeing here and there, turns out the line with the error is the one with the
$count = mysql_num_rows($result) or die(mysql_error());...

PHP Code:
    //connectie maken met DB
            $db = mysql_connect("localhost", "dieetopmaat_be", "dieetDB") or die(mysql_error());
            mysql_select_db(dieetopmaat_be, $db) or die(mysql_error());
    function check_presence($table, $row, $value){
        $sql = "SELECT *     FROM $table
                            WHERE $row = '$value'";
        $result = mysql_query($sql) or die(mysql_error());

        $count = mysql_num_rows($result) or die(mysql_error());

    if($count >= 1)
        return TRUE;
        return FALSE;

thanks to anyone who replies!

ps: dont mind the language, its written in dutch
cross the river styx - OranniS awaits!

#2 alpine

  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 24 September 2006 - 06:31 AM


function check_presence($table, $row, $value){
$sql = mysql_query("SELECT * FROM $table WHERE $row = '$value'") or die(mysql_error());
return false;
return true;


#3 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 25 September 2006 - 03:51 AM

To elaborate, 0 is a valid result, but will return false when used as a numerical comparison.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users