CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   2 errrors when i reg on my own script (http://www.codingforums.com/showthread.php?t=275892)

Chris-2k 10-09-2012 02:21 PM

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

Fou-Lu 10-09-2012 02:43 PM

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.

Chris-2k 10-10-2012 12:21 AM

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 10-10-2012 02:00 PM

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

Fou-Lu 10-10-2012 02:31 PM

What is the result of a the mysql_num_rows?

Chris-2k 10-10-2012 02:45 PM

what do you mean?

Fou-Lu 10-10-2012 02:50 PM

How many rows did this query return?

Chris-2k 10-10-2012 03:06 PM

0 rows, must be btw users are added in db............

Fou-Lu 10-10-2012 03:20 PM

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.

Chris-2k 10-10-2012 04:38 PM

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" ?

Fou-Lu 10-10-2012 04:57 PM

I mean print out the SQL and run it directly against a mysql client.

Chris-2k 10-10-2012 09:08 PM

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 


Fou-Lu 10-10-2012 10:07 PM

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.

Chris-2k 10-10-2012 10:28 PM

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..............

Fou-Lu 10-10-2012 10:36 PM

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.


All times are GMT +1. The time now is 06:06 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.