Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Log in doesn't work

    I've been busy with creating a login system but for some reason I get this error: "Warning: mysql_num_rows() expects parameter 1 to be resource, string given in **Path** on line 8".

    I don't see why because the $count should be 1, the "gebruikersnaam" does exist.

    gb=gebruikersnaam=username
    ww=wachtwoord=password

    PHP Code:
    <?php
    session_start
    ();
    include(
    'inc/config.php');
    if(
    $_POST) {
    $gb mysql_real_escape_string($_POST['gb']);
    $ww mysql_real_escape_string($_POST['ww']);
    $query = ("SELECT * FROM gebruikers WHERE gebruikersnaam = '$gb'");
    $count mysql_num_rows($query) or die(mysql_error());
    if(
    $count == 1) {
        echo 
    "User does exist";
    }
    } else {
        echo 
    "<form action='login.php' method='post'>
            <input type='text' name='gb' />
            <input type='password' name='ww' />
            <input type='submit' value='login' />
            </form>"
    ;
    }
    ?>
    Last edited by Krentenbol; 03-19-2012 at 06:50 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You haven't queried anything. $query is a string, using any type of fetch requires you to provide it with a result set resource, so you have to execute mysql_query.
    You'll need more than this though. The query only fetches on one field, which is presumably the username. You'll need to confirm that the password matches as well.
    Also, don't use if ($_POST). Use if (isset($_POST['gb'], $_POST['ww'])) instead.

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ahh I see I forget adding mysql_query, made it in a haste. This is to get the salt out of the database. Thank you for your help anyways.


  •  

    Posting Permissions

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