I'm trying to display a "Welcome back, <name>." to my blog when I log in back. I'm using php to access the database, get the name and last name of the username currently in $_SESSION['username'], and then print it back in the index.
So the function to query the database is:
function get_full_name($username){
$real = array();
$query = mysql_query("SELECT `name`, `last` FROM `users` WHERE `user` = `{$username}`");
$row = mysql_num_rows($query);
foreach($row as $k => $v)
{
$real[$k] = $v;
}
return $real;
}
Then the part of the html where it calls the function above:
<div id="menu">
<?php
$temp = $_SESSION['username'];
$real[] = get_full_name($temp);
if(isset($_SESSION['username']))
{
echo '<br />'.'Welcome back, '. $real['name'] . '.';
}
?>
</div>
The output of the above codes is:
Welcome back, .
var_dump($real) gives:
array(1) { [0]=> array(0) { } }
var_dump($real) after changing to mysql_fectch_assoc:
array(0) { }
- Fixed: The error was not using the single quotes ' {$username} '
By changing them, it worked like a charm, cheers to all!