Cannot get user info to show up
Moderator: General Moderators
Re: Cannot get user info to show up
Yes, the login part works. I've used my correct username and it's logged me in, but I can't get the welcome message up with the user's username displayed.
What would you suggest?
What would you suggest?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Cannot get user info to show up
You understand the implications of this? If I know the admins username I can log in with this permissions no problem..khushbush wrote:Yes, the login part works. I've used my correct username and it's logged me in, but I can't get the welcome message up with the user's username displayed.
What would you suggest?
As for not being able to login, try adding some debugging..
Code: Select all
$query = "SELECT username FROM user WHERE userid = $user";
$result = mysql_query($query) or die(mysql_error());
echo 'Users found: '. mysql_num_rows($result));
echo '<pre>'. print_r(mysql_fetch_assoc($result), true) .'</pre>';
echo '.Welcome <b>'. $row['username'] .'</b>, you are logged in. <br><br>'
.'[<a href="userinfo.php?user='. $row['username'].'">My Details</a>] '
.'[<a href="useredit.php">Edit Account</a>] ';
exit();
Re: Cannot get user info to show up
Oh yes, I will be including some password verification too. Thanks for the reminder though.
I'm just trying to get this to work first. And...it doesn't.
It showed the logout link though. And the 'Logged In' title. That's it.
I'm just trying to get this to work first. And...it doesn't.
It showed the logout link though. And the 'Logged In' title. That's it.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Cannot get user info to show up
Please post the exact output of the script I posted.khushbush wrote:Oh yes, I will be including some password verification too. Thanks for the reminder though.
I'm just trying to get this to work first. And...it doesn't.
It showed the logout link though. And the 'Logged In' title. That's it.
Re: Cannot get user info to show up
Here is the output:
Logged In
[Logout]
Logged In
[Logout]
Last edited by khushbush on Tue Apr 08, 2008 11:30 am, edited 1 time in total.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Cannot get user info to show up
What is the output of this code
Code: Select all
$query = "SELECT username FROM user WHERE userid = $user";
$result = mysql_query($query) or die(mysql_error());
echo 'Users found: '. mysql_num_rows($result));
echo '<pre>'. print_r(mysql_fetch_assoc($result), true) .'</pre>';
echo '.Welcome <b>'. $row['username'] .'</b>, you are logged in. <br><br>'
.'[<a href="userinfo.php?user='. $row['username'].'">My Details</a>] '
.'[<a href="useredit.php">Edit Account</a>] ';
exit();
Re: Cannot get user info to show up
Oh...
Here's the output I got:
Logged In
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
I hope that that is what you meant...
Here's the output I got:
Logged In
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
I hope that that is what you meant...
Re: Cannot get user info to show up
Your SQL error is this:
$query = "SELECT username FROM user WHERE userid = $user";
It should be '$user', not $user.
$query = "SELECT username FROM user WHERE userid = $user";
It should be '$user', not $user.
Re: Cannot get user info to show up
Thanks, bovermyer...nearly there...
Here's what I got after making the changes:
Logged In
Users found: 0
Welcome , you are logged in.
[My Details] [Edit Account]
Username still not showing up and it's not counting the number of users in the database.
Here's what I got after making the changes:
Logged In
Users found: 0
Welcome , you are logged in.
[My Details] [Edit Account]
Username still not showing up and it's not counting the number of users in the database.
Re: Cannot get user info to show up
Ok, the current code so far:
I've realised that the problem lies within not specifying $row as a variable. $row should be:
I tried that...and it didn't work. Is there anything else that might work? Could it be that the GET method doesn't work either?
Code: Select all
echo "<h1>Logged In</h1>";
$user = mysql_real_escape_string($_GET['userid']);
$query = "SELECT username FROM user WHERE userid = '$user'";
$result = mysql_query($query) or die(mysql_error());
echo 'Users found: '. mysql_num_rows($result);
echo '<pre>'. print_r(mysql_fetch_assoc($result), true) .'</pre>';
echo 'Welcome <b>'. $row['username'] .'</b>, you are logged in. <br><br>'
.'[<a href="userinfo.php?user='. $row['username'].'">My Details</a>] '
.'[<a href="useredit.php">Edit Account</a>] ';
exit();
Code: Select all
$row=mysql_fetch_row($result);Re: Cannot get user info to show up
Could you post all of your code so far as a .zip archive? I'd like to see everything related to the authentication.
Re: Cannot get user info to show up
I GOT IT WORKING!!!
Here's the code:
I just had to specify $_SESSION within a variable...and then within the html...and it showed the username!! YAY!! I'm really very happy!
Thanks ever so much for all your help, everyone!
Here's the code:
Code: Select all
$user = mysql_real_escape_string($_SESSION['userid']);
$query = "SELECT username FROM user WHERE userid = '$user'";
$result = mysql_query($query) or die(mysql_error());
echo "Welcome <b>". $_SESSION['username'] ."</b>, you are logged in. <br><br>"
."[<a href=\"userinfo.php?user=$session->username\">My Details</a>] "
."[<a href=\"useredit.php\">Edit Account</a>] ";
if($session->isAdmin()){
echo "[<a href=\"admin.php\">Admin Center</a>] ";
}
echo "[<a href=\"process.php\">Logout</a>]";
}
else {
header("Location: main.php");
}
?>
Thanks ever so much for all your help, everyone!
Re: Cannot get user info to show up
Glad you got it figured out. 