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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts

    2 errrors when i reg on my own script

    hi

    well...

    i'm getting 2 errors when registering on my own script, can any1 8help me solve.

    1st error:
    Code:
    mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 8
    here's the related func:
    PHP Code:
        function login_check($email$password) {
            
    $email mysql_real_escape_string($email);
            
            
    $q mysql_query("SELECT user_id FROM users WHERE email = '"$email ."' AND password = '"md5($password) ."'");
            
            return (
    mysql_result($q0) == 1) ? true false;
        } 
    2nd error:
    Code:
    mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 10
    here's the related func:
    PHP Code:
        function user_exists($email)
        {
            
    $email mysql_real_escape_string($email);
            
            
    $userExists mysql_query("SELECT * FROM users WHERE email='"$email ."'");
            
            return (
    mysql_result($userExists0) == 1) ? true false;
        } 
    thanks

  • #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
    Both the same error effectively.
    You have no results in your query, so therefore you cannot move to the first record. Use mysql_num_rows first to verify you have records in the resource.
    Hopefully you're not making a habit of using mysql_result. Its slow, and if you were to run both of these blocks in the same script then you query twice for information that isn't required. Query once for any information you need and use PHP to lookup what it needs from the resultset or a stored result. It's fine if you only call one and only need one at a time though, but since you can be limited in querycount per hour, you should be doing whatever you can to reduce the number of queries required.

  • #3
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    Thanks, now when i've regged it says: credentials not found, btw they're in the db??

    here's the edited func:
    PHP Code:
        function user_exists($email)
        {
            
    $email mysql_real_escape_string($email);
            
            
    $userExists mysql_query("SELECT * FROM users WHERE email='"$email ."'");
            
            return (
    mysql_num_rows($userExists) == 1) ? true false;
        } 

  • #4
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    sorry, this func is the 1........
    PHP Code:
        function login_check($email$password) {
            
    $email mysql_real_escape_string($email);
            
            
    $q mysql_query("SELECT user_id FROM users WHERE email = '"$email ."' AND password = '"md5($password) ."'");
            
            return (
    mysql_num_rows($q) == 1) ? true false;
        } 
    says : credentials not found, the ARE in te db......

    any help..
    thx

  • #5
    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
    What is the result of a the mysql_num_rows?

  • #6
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    what do you mean?

  • #7
    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
    How many rows did this query return?

  • #8
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    0 rows, must be btw users are added in db............

  • #9
    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
    Not according to that query there isn't matching records.
    Parse the statement in use and print it out. Run that same against the mysql client and see what it pulls up. It hasn't failed, assuming you have error reporting on. You should add an or die(mysql_error()) to the query though to verify.

  • #10
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    i added or die:
    PHP Code:
        function login_check($email$password) {
            
    $email mysql_real_escape_string($email);
            
            
    $q mysql_query("SELECT user_id FROM users WHERE email = '"$email ."' AND password = '"md5($password) ."'") or die mysql_error()w;
            
            return (
    mysql_num_rows($q) == 1) ? true false;
        } 
    the page doesn't die?

    i don't see what ya mean by "parse and print it" ?

  • #11
    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
    I mean print out the SQL and run it directly against a mysql client.

  • #12
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    Ok done that, gives me:
    Code:
    SELECT user_id FROM users WHERE email = 'testing@123.net' AND password = '6bb5afb249faf144816989497934fd80'
    also: Credentials not found + when run via phpmyadmin, it's working fine....

    what could the prob be?

    here's all my user funcs:
    PHP Code:
    // User Funcs
        
    function login_check($email$password) {
            
    $email mysql_real_escape_string($email);
            
            
    $query mysql_query("SELECT * FROM users WHERE email = '"$email ."' AND password = '"md5($password) ."'")  or die(mysql_error());
            echo 
    "SELECT user_id FROM users WHERE email = '"$email ."' AND password = '"md5($password) ."'";
            
            return (
    mysql_num_rows($query) > 0) ? true false;
        }

        function 
    loggedin()
        {
            return isset(
    $_SESSION['user_id']);
        }

        function 
    user_data() {
            
    $args func_get_args();
            
    $fields implode(','$args);
            
            
    $query mysql_query("SELECT $fields FROM users WHERE user_id ='".$_SESSION['user_id']."'") or die(mysql_error());
            
    $result mysql_fetch_assoc($query); 
            foreach(
    $args as $data)
            {
                
    $args[$data] = $result[$data];
            }
            return 
    $result;
        }

        function 
    add_user($email$name$password)
        {
            
    $email mysql_real_escape_string($email);
            
    $name mysql_real_escape_string($name);
            
            
    mysql_query("INSERT INTO users VALUES ('', '"$email ."','".  $name ."','"md5($password) ."','member','".date('D M, Y')."','flag')") or die(mysql_error());
            
            return 
    mysql_insert_id();
        }

        function 
    user_exists($email)
        {
            
    $email mysql_real_escape_string($email);
            
            
    $userExists mysql_query("SELECT * FROM users WHERE email='"$email ."'");
            
            return (
    mysql_num_rows($userExists) == 1) ? true false;
        }
    // End User Funcs 

  • #13
    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
    So in PHPMyAdmin, that above runs fine and produces exactly one record, but calling login_check returns false?

    See if that has a valid count off of it:
    PHP Code:
    $qry mysql_query('SELECT count(*) FROM users WHERE email = "' $email '" AND password = "' md5($password) . '"') or die(mysql_error());
    $cnt mysql_result($qry0);
    printf("Count: %d" PHP_EOL$cnt); 
    If that produces a count of 1 (or greater than, but I assume email is unique), then check for this:
    PHP Code:
    printf("mysql.trace_mode = %d" PHP_EOLini_get('mysql.trace_mode')); 
    If that pulls out at 1, then grab the PHP version via PHP_VERSION or phpversion() and post that.

  • #14
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    It shows: Count: 0

    something i forgot tomention is - as ssoon as i've regged, that's when i get "credits not found", coz it logs in straiight awy..............

  • #15
    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
    Does it work anytime after an immediate login?
    What is the chain of function calls here; none of them currently call any other, so I can't see the process.
    Only thing that stands out is this:
    PHP Code:
            foreach($args as $data)
            {
                
    $args[$data] = $result[$data];
            } 
    It is a completely useless traversal; assigning to $args cannot be done as func_get_arg[s] is incapable of retrieving data as reference.


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

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