I would like to have "Welcome, [user's name]!" appear on a page of my website.
I perform this query:
Option 1 I tried:
$first_name = mysql_query("SELECT first_name FROM users WHERE id = $user_id");
echo "Welcome, " . $first_name . "!";
Option 2 I tried:
$users = mysql_query("SELECT * FROM users WHERE id = $user_id");
if (count($user) == 1)
{
// first (and only) row -- meaning only one user in this array
$user = $users[0];
echo "first_name: " . $user['first_name'] . "!";
}
A row in my users table looks like this: id | first_name | last_name | email | password
I have tested and I successfully have the user's id. My SQL query is also tested and works.
This is php code inserted into HTML code.
I'm struggling in accessing the first_name of the user -- any help is appreciated!