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.

<?php
//connection string
$con = mysql_connect('127.0.0.1','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_start();
$_SESSION['auth'] = 1;
$_SESSION['firstname']=$name;
header("Location: useraccount.php");
}
else
{
//echo 
}
?>

Recommended Answers

All 2 Replies

write echo in if statement and header in else statement

Member Avatar for diafol

often helps to place

session_start()

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.