Jump to content

simply result error


yahn

Recommended Posts

here is my code:
[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']);
[/code]

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?
Link to comment
Share on other sites

[!--quoteo(post=352718:date=Mar 7 2006, 09:09 PM:name=yahn)--][div class=\'quotetop\']QUOTE(yahn @ Mar 7 2006, 09:09 PM) [snapback]352718[/snapback][/div][div class=\'quotemain\'][!--quotec--]
here is my code:
[code=php:0]
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']);
[/code]

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.
Link to comment
Share on other sites

[!--quoteo(post=352725:date=Mar 7 2006, 09:24 PM:name=yahn)--][div class=\'quotetop\']QUOTE(yahn @ Mar 7 2006, 09:24 PM) [snapback]352725[/snapback][/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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.