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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    PHP Code:
    Warningmysql_result(): supplied argument is not a valid MySQL result resource in /home/******/domains/*********.***.**/public_html/admin/func/user.func.php on line 10
    Unable to log you in 
    (*-is hidden by me)

    PHP Code:
    <?php

    function logged_in() {
        return isset(
    $_SESSION['id']);
    }

    function 
    login_check($username$password) {
        
    $username mysql_real_escape_string($username);
        
    $login_query mysql_query("SELECT COUNT(`id`) AS `count`, `id` FROM `config` WHERE `username` = '$username' AND `password` = '".md5($password)."'");
        return (
    mysql_num_rows($login_query0) == 1) ? mysql_num_rows($login_query0'id') : false;
    }

    function 
    user_data() {
        
    $args func_get_args();
        
    $fields '`'.implode('`, `'$args).'`';
        
        
    $query mysql_query("SELECT $fields FROM config WHERE id = '".$_SESSION['id']."'");
        
    $query_result mysql_fetch_assoc($query);
        foreach (
    $args as $field) {
            
    $args[$field] = $query_result[$field];
        }
        return 
    $args;
    }

    function 
    genRandomString() {
        
    $length 10;
        
    $characters '0123456789abcdefghijklmnopqrstuvwxyz';
        
    $string '';    
        for (
    $p 0$p $length$p++) {
            
    $string .= $characters[mt_rand(0strlen($characters) -1)];
        }
        return 
    $string;
    }
    ?>
    Line 10:
    PHP Code:
    return (mysql_num_rows($login_query0) == 1) ? mysql_num_rows($login_query0'id') : false
    I can't log in
    Last edited by Inigoesdr; 11-13-2011 at 03:21 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You're usage is wrong, but the error doesn't match your code. The line does, and the actual syntax error appears to as well, so methinks its been modified since providing it here.
    You cannot use mysql_num_rows with a second parameter (or third). It only takes a resource. A count will always provide at least 1 record. Given the error you have, I expect that this is actually mysql_result, which does accept a second parameter to indicate the field (and matches your error itself). Dropping the count aggregate seems easier, then you can just count the results with mysql_num_rows, which should be 1 or 0. If its more than one, you have a unique constraint issue on your hands since it allows multiple users with the same username and password (which chances are you will not have).

    The error you have overall is a failure of your query itself. Since the variable names are correct, that indicates that the result of a mysql_query has returned false, which in the event of a select is a SQL syntax error. Check your column names to verify. You can add an or die(mysql_error()); chain to the mysql_query itself to dump a mysql error on a failure.


  •  

    Posting Permissions

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