Enjoy an ad free experience by logging in. Not a member yet?
Register .
10-09-2012, 02:21 PM
PM User |
#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 ( $q , 0 ) == 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 ( $userExists , 0 ) == 1 ) ? true : false ;
}
thanks
10-09-2012, 02:43 PM
PM User |
#2
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 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.
10-10-2012, 12:21 AM
PM User |
#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 ; }
10-10-2012, 02:00 PM
PM User |
#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
10-10-2012, 02:31 PM
PM User |
#5
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
What is the result of a the mysql_num_rows?
10-10-2012, 02:45 PM
PM User |
#6
Regular Coder
Join Date: May 2011
Posts: 303
Thanks: 29
Thanked 0 Times in 0 Posts
what do you mean?
10-10-2012, 02:50 PM
PM User |
#7
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
How many rows did this query return?
10-10-2012, 03:06 PM
PM User |
#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............
10-10-2012, 03:20 PM
PM User |
#9
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 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-10-2012, 04:38 PM
PM User |
#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" ?
10-10-2012, 04:57 PM
PM User |
#11
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
I mean print out the SQL and run it directly against a mysql client.
10-10-2012, 09:08 PM
PM User |
#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
10-10-2012, 10:07 PM
PM User |
#13
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 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 ( $qry , 0 );
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_EOL , ini_get ( 'mysql.trace_mode' ));
If that pulls out at 1, then grab the PHP version via PHP_VERSION or phpversion() and post that.
10-10-2012, 10:28 PM
PM User |
#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..............
10-10-2012, 10:36 PM
PM User |
#15
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 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.
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 11:52 PM .
Advertisement
Log in to turn off these ads.