I am having trouble retrieving some data from my database.
I’m trying to display a user’s name in the upper corner when they log in. It will say “Welcome, (Name)”
I can get it to display the user’s username, but I want their real name displayed, which they supply when they register.
Here is where the name should display:
[php]<?php
session_start();
if($_SESSION[’$loggedin’] == “yes”) {
?>
Welcome
<?php include('db_variables/myname.php'); $_SESSION['$myname'] = $myname; echo $myname; ?>Log Out <?php } else { ?> <?php } ?>[/php]
And here is where I am attempting to retrieve the name variable:
[php]<?php
session_start();
include (‘config_game_db.php’);
$_SESSION[’$myusername’] = $myusername;
//$sql = “SELECT * FROM users WHERE username = ‘$myusername’”;
//$result = mysql_query($sql) or die (mysql_error());
// while($row = mysql_fetch_array($result))
// {
// $myid= $row[‘id’];
// $myname = $row[‘name’];
// }
$result = mysql_query(“SELECT id,name FROM users WHERE username = ‘$myusername’”);
if (!$result) {
echo 'Could not run query: ’ . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
$myid = $row[0]; // id
$myname = $row[1]; // name
$_SESSION[’$myname’] = $myname;
?>[/php]
(The commented out section is another method I tried to fetch the data)
The second file is the “myname.php” file.
The site displays “Welcome” with no problem once you are logged in. But the problem is it doesn’t display anything where I echo the user’s real name. But like I said before, I can get it to echo the username with no problem, so I don’t get why I can’t get the name to work.
I’ve been scratching my head for two days trying to figure this one simple thing out! I feel like I’m so close but just missing something?