Here, I have created a php mysql login page. I am a newbie so please also comment on my code too.
I have this login page where after entering the correct data i am getting welcome "id" instead of "username".
I want to know what i am doing wrong here. :(
login.php
<?php
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$username=addslashes($_POST['username']);
$password=addslashes($_POST['password']);
//connect to database
$con=mysql_connect("localhost","","") or die();
$db=mysql_select_db("dashboard") or die();
//execute query
$query ="SELECT username, password from `login` where username=$username";
$result=mysql_query($query);
if($username='username' && $password='password')
{
$_SESSION['username']=$username;
header("Location:dashboard.php");
}
else
{
echo "You got credentials wrong";
}
}
?>
<form method="post" action="<?php htmlspecialchars("PHP_SELF"); ?>">
<label>Username :</label><input type="text" name="username"></br>
<label>Password:</label><input type="password" name="password"></br>
<br/>
<input type="submit" value="submit"></br>
</form>
dashboard.php
<?php
session_start();
echo "Welcome ". $_SESSION['username'];
?>
<a href="logout.php">Logout</a>
logout.php
<?php
session_destroy();
header("Location:login.php");
?>