I am trying to Echo $_SESSION["myusername"]. I can login to my page but I can not Echo myusername. I get the following error. Undefined variable: myusername in C:....
checklogin.php page is as follows
<?php
ob_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="techdb"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
$_SESSION['myusername']=$myusername;
$_SESSION['mypassword']=$mypassword;
header("location:technicianform.php");
} else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
And my technicianform.php page is
<?php
session_start();
if( isset($_SESSION['$myusername']) ){
header("location:checklogin.php");
}
?>
<html>
<body>
<p>Login Successful</p>
<?php echo $_SESSION["myusername"]; ?>
<p><br/>
<br/><br/><a href='Logout.php'>Click here to log out</a></p>
</body>
</html>
Login process works but I can't seem to echo myusername. Your help is much appreciated.