<?php
ob_start();
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="login.php">
user name : <input type="text" name="username">
password : <input type="text" name="password">
<input type="submit" name="submit">
</form>
</body>
</html>
<?php
include ('D_Base_Connect.php');
if(isset($_POST['submit'])){
//$username=mysql_real_escape_string($_POST['username']);
//$password=mysql_real_escape_string($_POST['password']);
$username =$_POST['username'];
$password = $_POST['password'];
$values="SELECT * from userdetails where username='$username' and password='$password' ";
$query=mysql_query($values,$conn);
if (mysql_num_rows($query)==0)
{echo "you are not logged in ";
}
else{
while($row = mysql_fetch_array($query)){
$fetched_userid = $row['userid'];
$fetched_username = $row['username'];
$fetched_email = $row['email'];
$fetched_password = $row['password'];
$fetched_usertype = $row['usertype'];
if($username == $fetched_username && $password == $fetched_password){
$_SESSION['fetchedid'] = $fetched_userid;
$_SESSION['fetchedusername'] = $fetched_username;
$_SESSION['fetchedemail'] = $fetched_email;
$_SESSION['fetchedusertype'] = $fetched_usertype;
header("Location: home.php");
}else{
header("Location: logout.php");
}
} // end of the while
} // end of the else
}
?>
the above is my login page which works fine but when i go to another page
<?php
ob_start();
session_start();
include ('D_Base_Connect.php');
if (!empty($_SESSION['fetchedid'])) {
$fetched_userid = $_SESSION['fetchedid'];
}
$fetched_userid =$_SESSION['fetchedid'];
$fetched_username=$_SESSION['fetchedusername'];
$fetched_email= $_SESSION['fetchedemail'];
$fetched_usertype=$_SESSION['fetchedusertype'];
?>
it gives erros
Notice: Undefined index: fetchedid in C:\xampp\htdocs\AA\home.php on line 9
Notice: Undefined index: fetchedusername in C:\xampp\htdocs\AA\home.php on line 10
Notice: Undefined index: fetchedemail in C:\xampp\htdocs\AA\home.php on line 11
Notice: Undefined index: fetchedusertype in C:\xampp\htdocs\AA\home.php on line 12