Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-09-2012, 02:21 PM   PM User | #1
Chris-2k
Regular Coder

 
Join Date: May 2011
Posts: 303
Thanks: 29
Thanked 0 Times in 0 Posts
Chris-2k is an unknown quantity at this point
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
Chris-2k is offline   Reply With Quote
Old 10-09-2012, 02:43 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 10-10-2012, 12:21 AM   PM User | #3
Chris-2k
Regular Coder

 
Join Date: May 2011
Posts: 303
Thanks: 29
Thanked 0 Times in 0 Posts
Chris-2k is an unknown quantity at this point
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;
    } 
Chris-2k is offline   Reply With Quote
Old 10-10-2012, 02:00 PM   PM User | #4
Chris-2k
Regular Coder

 
Join Date: May 2011
Posts: 303
Thanks: 29
Thanked 0 Times in 0 Posts
Chris-2k is an unknown quantity at this point
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
Chris-2k is offline   Reply With Quote
Old 10-10-2012, 02:31 PM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
What is the result of a the mysql_num_rows?
Fou-Lu is offline   Reply With Quote
Old 10-10-2012, 02:45 PM   PM User | #6
Chris-2k
Regular Coder

 
Join Date: May 2011
Posts: 303
Thanks: 29
Thanked 0 Times in 0 Posts
Chris-2k is an unknown quantity at this point
what do you mean?
Chris-2k is offline   Reply With Quote
Old 10-10-2012, 02:50 PM   PM User | #7
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
How many rows did this query return?
Fou-Lu is offline   Reply With Quote
Old 10-10-2012, 03:06 PM   PM User | #8
Chris-2k
Regular Coder

 
Join Date: May 2011
Posts: 303
Thanks: 29
Thanked 0 Times in 0 Posts
Chris-2k is an unknown quantity at this point
0 rows, must be btw users are added in db............
Chris-2k is offline   Reply With Quote
Old 10-10-2012, 03:20 PM   PM User | #9
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 10-10-2012, 04:38 PM   PM User | #10
Chris-2k
Regular Coder

 
Join Date: May 2011
Posts: 303
Thanks: 29
Thanked 0 Times in 0 Posts
Chris-2k is an unknown quantity at this point
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" ?
Chris-2k is offline   Reply With Quote
Old 10-10-2012, 04:57 PM   PM User | #11
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I mean print out the SQL and run it directly against a mysql client.
Fou-Lu is offline   Reply With Quote
Old 10-10-2012, 09:08 PM   PM User | #12
Chris-2k
Regular Coder

 
Join Date: May 2011
Posts: 303
Thanks: 29
Thanked 0 Times in 0 Posts
Chris-2k is an unknown quantity at this point
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 
Chris-2k is offline   Reply With Quote
Old 10-10-2012, 10:07 PM   PM User | #13
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 10-10-2012, 10:28 PM   PM User | #14
Chris-2k
Regular Coder

 
Join Date: May 2011
Posts: 303
Thanks: 29
Thanked 0 Times in 0 Posts
Chris-2k is an unknown quantity at this point
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..............
Chris-2k is offline   Reply With Quote
Old 10-10-2012, 10:36 PM   PM User | #15
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
latd

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:52 PM.


Advertisement
Log in to turn off these ads.