yahn Posted March 8, 2006 Share Posted March 8, 2006 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? Quote Link to comment Share on other sites More sharing options...
greycap Posted March 8, 2006 Share Posted March 8, 2006 [!--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 errorWhat 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. Quote Link to comment Share on other sites More sharing options...
yahn Posted March 8, 2006 Author Share Posted March 8, 2006 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 Link to comment Share on other sites More sharing options...
greycap Posted March 8, 2006 Share Posted March 8, 2006 [!--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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.