Hi, I'm trying to display the first name of the username using session after they entered username and password. I'm not sure what went wrong with my code. Any suggestion? Thank you.

//connection string
$con = mysql_connect('','root')or die(mysql_error());

//select the database
mysql_select_db('local',$con) or die("Unable to connnect!");

//mySQL query 
$sql1 ="SELECT username, password, fname FROM tblLogin INNER JOIN tblUser ON tblLogin.email = tblUser.email WHERE username='".$_POST['username']."' AND password='".sha1($_POST['password'])."'";
//check whether the input is valid?
$result= mysql_query($sql1,$con) or die("Error in query:$query.".mysql_error());

if (mysql_num_rows($result) == 1)
$row = mysql_fetch_array($result)
$name = $row['fname'];
$_SESSION['auth'] = 1;
header("Location: useraccount.php");

write echo in if statement and header in else statement

Member Avatar


often helps to place


at the top of the page (not in a conditional block)