hello guys, i am an it student and im confuse how to display the user’s firstname when he or she login using session.
here is my login page code:
[php]<?php
session_start();
$host = “localhost”;
$user = “root”;
$pass = “”;
$db = “student”;
mysql_connect($host, $user, $pass);
mysql_select_db($db);
if (isset($_POST[‘username’])) {
$username = $_POST[‘username’];
$password = $_POST[‘password’];
$user = $_POST[‘username’];
$pass = $_POST[‘password’];
$sql = “SELECT * FROM student WHERE username=’”.$username."’ AND password=’".$password."’ LIMIT 1";
$res = mysql_query($sql);
if (mysql_num_rows($res) == 1 ) {
$user = $_POST['username'];
$pass = $_POST['password'];
$sql2 = "select * from student where username = '".$username."' ";
$resfname = mysql_query($sql2);
$_SESSION['fname'] = $resfname;
echo "login successful.";
header("Location: sad52/studentpage.php");
exit();
}
else {
echo"invalid username or password.";
exit();
}}
?>
Student
Log in to My Account
UserName
Password
<div id="column_r" style="left: -1px; top: 0px; width: 193px">
[/php]
and here is the code of the page when the user login
[php]<?php
session_start();
$host = “localhost”;
$user = “root”;
$pass = “”;
$db = “student”;
if(isset($_POST[‘submit’]))
{
echo $_SESSION['fname'];
}
?>
[/php]
hope you guys can help me…
all your replies will be appreciated.
thank you www.phphelp.com