this is my login page coding. my login form html coding and php coding is in same page. now if login successful it will redirect to mainpage.php and then if login failure it will show the error message on same page (login.php). how to do that? i tried something but its not working... how to use php session here?
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$uname = $_POST['username'];
$pwd = $_POST['password'];
$uname = htmlspecialchars($uname);
$pwd = htmlspecialchars($pwd);
$user = "root";
$pass = "";
$database = "data";
$link = mysql_connect( "localhost", $user, $pass );
if(!$link)
{
die ( "Could not connect to MySQL : " .mysql_error() );
}
mysql_select_db ($database, $link) or die ( "Could not select MySQL $database : " .mysql_error() );
$result = mysql_query( "SELECT * FROM emp_register WHERE emp_username = '$uname' AND emp_password = '$pwd'" );
while($row = mysql_fetch_array($result))
{
if($row["emp_username"] == $uname && $row["emp_password"] == $pwd)
{
echo "Welcome $uname";
}
else
{
echo "Username and Password does not match";
}
}
}
?>