I have a login script that checks the username and password against info stored in a database table named users.
But, I also have the user's real name stored as name in the same table. So the table has the following fields:
username | password | name
After the script verifies the login, I want to pull out the name of the person logging in so that I can give them a personal greeting..
Here's a snippet of what I have:
// query the database to see if there is a matching record
$query="SELECT * FROM users WHERE username='$username' and password='$password' ";
$result=mysql_query($query)
or die ("Query failed.");
if (mysql_num_rows($result) > 0 )
{
// name and password combination are correct
$valid_user=$username;
session_register("valid_user");
Here's where the personal greeting comes in:
$time = localtime (time ( ) );
$hour = $time[2];
if ($hour > 18)
{ echo "<br><p><font size=\"2\"> Good evening <b>".$name."!</b></font></p>"; }
else if ($hour > 12)
{ echo "<br><p><font size=\"2\"> Good afternoon <b>".$name."!</b></font></p>"; }
else
{ echo "<br><p><font size=\"2\"> Good morning <b>".$name."!</b></font></p>"; }
So you see, I need to get that name out and store it in $name.
I thought the following might work, but it doesn't:
$name=mysql_query("SELECT name FROM users WHERE username='$username' ");
It gives me the following "Good morning Resource id #4!"
What am I doing wrong??
Thanks!!