Page 2 of 2

Re: Cannot get user info to show up

Posted: Tue Apr 08, 2008 11:06 am
by khushbush
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?

Re: Cannot get user info to show up

Posted: Tue Apr 08, 2008 11:08 am
by John Cartwright
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?
You understand the implications of this? If I know the admins username I can log in with this permissions no problem..

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>] &nbsp;&nbsp;'
       .'[<a href="useredit.php">Edit Account</a>] &nbsp;&nbsp;';
 
exit();
 

Re: Cannot get user info to show up

Posted: Tue Apr 08, 2008 11:20 am
by khushbush
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

Posted: Tue Apr 08, 2008 11:25 am
by John Cartwright
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.
Please post the exact output of the script I posted.

Re: Cannot get user info to show up

Posted: Tue Apr 08, 2008 11:29 am
by khushbush
Here is the output:

Logged In

[Logout]

Re: Cannot get user info to show up

Posted: Tue Apr 08, 2008 11:30 am
by John Cartwright
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>] &nbsp;&nbsp;'
       .'[<a href="useredit.php">Edit Account</a>] &nbsp;&nbsp;';
 
exit();
 

Re: Cannot get user info to show up

Posted: Tue Apr 08, 2008 11:33 am
by khushbush
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...

Re: Cannot get user info to show up

Posted: Tue Apr 08, 2008 11:51 am
by bovermyer
Your SQL error is this:

$query = "SELECT username FROM user WHERE userid = $user";

It should be '$user', not $user.

Re: Cannot get user info to show up

Posted: Tue Apr 08, 2008 12:00 pm
by khushbush
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.

Re: Cannot get user info to show up

Posted: Tue Apr 08, 2008 12:16 pm
by khushbush
Ok, the current code so far:

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>] &nbsp;&nbsp;'
       .'[<a href="useredit.php">Edit Account</a>] &nbsp;&nbsp;';
 
exit();
 
I've realised that the problem lies within not specifying $row as a variable. $row should be:

Code: Select all

$row=mysql_fetch_row($result);
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?

Re: Cannot get user info to show up

Posted: Tue Apr 08, 2008 12:26 pm
by bovermyer
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

Posted: Tue Apr 08, 2008 3:25 pm
by khushbush
I GOT IT WORKING!!! :D :D :D

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>] &nbsp;&nbsp;"
       ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;";
   if($session->isAdmin()){
      echo "[<a href=\"admin.php\">Admin Center</a>] &nbsp;&nbsp;";
   }
   echo "[<a href=\"process.php\">Logout</a>]";
}
 
else {
  header("Location: main.php");
}
?>
 
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! :D

Thanks ever so much for all your help, everyone! :)

Re: Cannot get user info to show up

Posted: Wed Apr 09, 2008 8:31 am
by bovermyer
Glad you got it figured out. 8)