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 9 of 9
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Warning: mysql_result(): supplied argument is not a valid MySQL result resource

    I have am trying(unsuccessfully) to create a login script. I get the following error

    heres the code:

    Code:
    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in test_login.php on line 13
    PHP Code:
    <?php  
    include ('includes/db.php'); 
    array_pop($_POST);  
    if ( 
    get_magic_quotes_gpc() ) {  
        
    $_POSTarray_map('stripslashes'$_POST);  
    }  

    $usernamemysql_real_escape_string(trim($_POST['username']));  
    $passwordmysql_real_escape_string(trim($_POST['password']));  

    $sqlsprintf("SELECT COUNT(*) AS login_match FROM `users` WHERE `username` = '%s' AND `user_password`= '%s'"$username$password);  
    $resmysql_query($sql);  
    $login_matchmysql_result($res0'login_match');  

    if ( 
    $login_match == ) {  
        echo 
    "This test worked"
    } else {  
        echo 
    "This test did not work"
        
    // not logged in  

    ?>
    line 13:

    PHP Code:
    $login_matchmysql_result($res0'login_match'); 
    I am wondering if anyone can suggest as to why this is happening?

  • #2
    New Coder
    Join Date
    Jul 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it was a simple error. I changed this line

    From:

    PHP Code:
    $resmysql_query($sql); 
    To:

    PHP Code:
    $resmysql_query($sql) or die(mysql_error()); 
    This told me that user_password was not valid..lol. A simple error
    I am running into another problem. It is not logining me in. I keep getting the error message

    PHP Code:
    } else { 
        echo 
    "This test did not work"
    Any suggestions as to why this is not loging in?

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Try echoing $login_match and see what is getting returned.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #4
    New Coder
    Join Date
    Jul 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it is echoing 0. So this means that there is something wrong with the way that I have $login_match setup.

    Could you suggest a better way

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What row are the username and password stored on? Have you read the manual on mysql_result()? http://us2.php.net/mysql_result
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    New Coder
    Join Date
    Jul 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    username is on row 0 and passowrd is on row 1

  • #7
    New Coder
    Join Date
    Jul 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it was a simple error. Thanks for your help. I had to use mysql_num_rows instead of mysql_result..lol

  • #8
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    the number of rows by
    SELECT COUNT(*) will always be 1, so I'm not convinced you will have fixed it.
    The query would need to be something like:
    SELECT username FROM...WHERE...
    and that will return 1 row when there is a valid match.

  • #9
    New Coder
    Join Date
    Jul 2006
    Location
    Portugal
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try something like this (untested)
    PHP Code:
     <?php   
    include ('includes/db.php');  
    array_pop($_POST);   
    if ( 
    get_magic_quotes_gpc() ) {   
        
    $_POSTarray_map('stripslashes'$_POST);   
    }   

    $usernamemysql_real_escape_string(trim($_POST['username']));   
    $passwordmysql_real_escape_string(trim($_POST['password']));   

    $sql "SELECT * FROM `users` WHERE username LIKE ".$username." AND user_password = ".$password."";   
    $query mysql_query($sql);   
    $res mysql_num_rows($query);   

    if ( 
    $res == ) {   
        echo 
    "This test worked";  
    } else {   
        echo 
    "This test did not work";  
        
    // not logged in   
    }  
    ?>
    it was a simple error. Thanks for your help. I had to use mysql_num_rows instead of mysql_result..lol
    Sorry, i didn't refresh my page and consequently didn't see your post.
    Liked my post? want my help in a project? MSN: geral'at'brunobernardino.com


  •  

    Posting Permissions

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