www.webdeveloper.com
Results 1 to 5 of 5

Thread: num_row errors

  1. #1
    Join Date
    Aug 2006
    Posts
    57

    num_row errors

    Hi, i need help to solve this case, I'm trying to create login forms, and i got errors it said
    "mysql_num_rows() expects parameter 1 to be resource, boolean given in line 18.

    i can't figure out what this mean and how to solve it. here is code, please see line 18 in bold where it said

    $count=mysql_num_rows($result);


    Code:
    ob_start(); 
    // Connect to server and select databse.
    include ('conn.php');
    // Define $myusername and $mypassword
    $myusername=$_POST['username'];
    $mypassword=$_POST['password'];
    // To protect MySQL injection (more detail about MySQL injection)
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    $sql="SELECT * FROM `members` WHERE username='$myusername' and password='$mypassword'";
    //echo  $sql;
    
    $result=mysql_query($sql);
    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    
    // If result matched $myusername and $mypassword, table row must be 1 row
    
    if($count==1){
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    echo $myusername;
    $_SESSION['myusername'] = $myusername;
    //header("location:login_success.php");
    }
    else {
    echo "";
    //header("location:index.php?a='failed'");
    }
    ob_flush();
    ?>

    can anyone help me what to write that code to solve this, because I'm still not get it.

    thanks.

    AM

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,604
    It means the query failed for some reason and returned a Boolean false instead of a query result resource. Therefore you need to debug your query and also consider adding some defensive coding, so that you only call mysql_num_rows() if the query did not fail (i.e. is not false).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2006
    Posts
    57
    like this!

    $sql="SELECT * FROM `members` WHERE username='$myusername' and password='$mypassword'";
    if(!$result) die ('Unable to run query:'.mysql_error());

    but i'm still getting new errors the result said "unable to run query).

    what this mean!

    AM

  4. #4
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    You might try running the query in phpMyadmin to make sure the query returns the right data. Is the conn.php connecting ok?

    It is not a good practice to store the password in a readable format. It is best to encrypt the password. That way if your site is hacked the passwords will not be stolen along with usernames. When encrypted you just re-encrypt the login and compare encrypted to encrypted.

  5. #5
    Join Date
    Oct 2012
    Posts
    3
    So I can assist you please report the errors you are getting with

    <?php
    error_reporting(E_ALL);
    ?>

    Post them here and help will come.

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