www.webdeveloper.com
Results 1 to 3 of 3

Thread: query says 0 but mysql_numrows returns 1?!?!

  1. #1
    Join Date
    Mar 2009
    Posts
    16

    query says 0 but mysql_numrows returns 1?!?!

    At my wit's end on this one...

    Every time I run this (with the querystring blank or set to some invalid text), the numrecs echo shows a value of 1 (and the code branches in that direction.) But in reality, there are ZERO records found.

    If I copy the echoed query from the screen and paste it into phpMyAdmin, it returns "0". Can anyone spot the problem?

    PHP Code:
        $qs=$_SERVER['QUERY_STRING'];
        
    $query " SELECT COUNT(*) FROM main WHERE UserCode = '" $qs "' ";
        echo 
    'querystring = "' $qs '"<br>query = "' $query '"<br>';
        
    $result mysql_query($query,$dblink) or die(mysql_error());
        
    $numrecs mysql_numrows($result);
        echo 
    'numrecs = ' $numrecs;
        if(
    $numrecs 1) {

            
    //    INVALID USER

            
    echo 'Recs = 0';
            
    Header"Location: ./login.php" );

        } else {

            
    //    VALID USER
    ?>
    <html>
    <head>
    . . . 

  2. #2
    Join Date
    Jun 2008
    Posts
    62
    Well, since you use
    Code:
    COUNT(*)
    there should always be exactly one record returned, the record containing the number of matches. That number may well be zero, but you have to check the actual value, not the number of rows returned, to find out.

  3. #3
    Join Date
    Mar 2009
    Posts
    16
    DOH! Thanks, Malgrim. (I feel like such an idiot! LOL)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles