Jump to content


Photo

simply result error


  • Please log in to reply
3 replies to this topic

#1 yahn

yahn
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 08 March 2006 - 03:09 AM

here is my code:
    if (!get_magic_quotes_gpc())
    {
        $_SESSION['username'] = addslashes($_SESSION['username']);
    }

    $name = $_SESSION['username'];
    $query = "SELECT user_pass FROM general_users WHERE user_name = '{$name}'";
    $pass = mysql_query($query);

    $password = mysql_result($pass, 0, 'user_pass'); // line 28
    $_SESSION['password'] = stripslashes($_SESSION['password']);

here is my error
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 4 in W:\www\connect.php on line 28[/quote]

What this code is suppose to do is keep you logged in using sessions.

This doesn't make sense to me because I use the same exact code to log in and it doesn't give an error, and the first time the page runs after you log in it doesn't give an error. Does anyone know what the problem is?

#2 greycap

greycap
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 08 March 2006 - 03:16 AM

[!--quoteo(post=352718:date=Mar 7 2006, 09:09 PM:name=yahn)--][div class=\'quotetop\']QUOTE(yahn @ Mar 7 2006, 09:09 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
here is my code:
	if (!get_magic_quotes_gpc())
	{
		$_SESSION['username'] = addslashes($_SESSION['username']);
	}

	$name = $_SESSION['username'];
	$query = "SELECT user_pass FROM general_users WHERE user_name = '{$name}'";
	$pass = mysql_query($query);

	$password = mysql_result($pass, 0, 'user_pass'); // line 28
	$_SESSION['password'] = stripslashes($_SESSION['password']);

here is my error
What this code is suppose to do is keep you logged in using sessions.

This doesn't make sense to me because I use the same exact code to log in and it doesn't give an error, and the first time the page runs after you log in it doesn't give an error. Does anyone know what the problem is?
[/quote]


Seems like youre editing your username every time the page is loaded.
$_SESSION['username'] = addslashes($_SESSION['username']);

Which is why it would work the first time, but not subsequent times.
instead, leave the $_S['username'] alone, and make that adjustment to $name when you access the db.

edit: the reason you are getting that error is because NO rows are returned. You should make sure that there are rows being returned by the query before you try to read them.

#3 yahn

yahn
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 08 March 2006 - 03:24 AM

I take the slashes out at the end of the code, either way I canged it and it still gives the same error. Does anything else seem like it could be causing a problem?

#4 greycap

greycap
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 08 March 2006 - 03:32 AM

[!--quoteo(post=352725:date=Mar 7 2006, 09:24 PM:name=yahn)--][div class=\'quotetop\']QUOTE(yahn @ Mar 7 2006, 09:24 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I take the slashes out at the end of the code, either way I canged it and it still gives the same error. Does anything else seem like it could be causing a problem?
[/quote]

It definately has to be something with that database query. The only way for mysql_result to fail when asking for the 0th paramater is for either no rows to be returned or an invalid query. Because $name is the only thing that isnt hardcoded into that query, and the fact that it works once, you have to be able to track it to that (or the database connection settings.)

Why not do a print $query at that point and see what the output is at run-time.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users