This question already has an answer here:
My SESSION username is Hassan
This is my PHP code:
$user = $_SESSION['username'];
echo $user;
$sql = mysql_query('SELECT `full_name` FROM `users` WHERE username="$user"');
$full_name = mysql_result($sql,0);
echo $full_name;
To make sure there is a $_SESSION['username']
I echo the $user
and the result I get is perfect, this is what I get when I goto home.php:
Hassan
Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 5 in C:\xampp\htdocs\PHP\Projects\UserSys\home.php on line 15
I have now ticked the correct answer, question solved close post.
</div>
You are trying to stick your $user
variable in a single-quote string. It won't be evaluated.
Simply change your query to use double quotes:
$sql = mysql_query("SELECT `full_name` FROM `users` WHERE username='$user'");
Though while this should fix your immediate issue, please realize you are using deprecated mysql_*
functions, and potentially opening yourself to SQL injection. You should be escaping your query params at least, ideally using prepared statements.