Hello there, anyone can help me about my problem, i want to display an error message when the user inputs invalid username and incorrect password. and i want to display it in the same form. im new in php.
These are my codes:
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$db=mysql_connect('localhost','root','') or die('Cannot connect to MySQL!');
@mysql_select_db('dbriomra')or die('Cannot connect to database');
// Retrieve username and password from database according to user's input
$login = mysql_query("SELECT * FROM login WHERE (username = '" . mysql_real_escape_string($_POST['compid']) . "') and (password = '" . mysql_real_escape_string($_POST['pword']) . "')");
// Check username and password match
if (mysql_num_rows($login) == 1) {
// Set username session variable
$_SESSION['username'] = $_POST['compid'];
// Jump to secured page
header('Location: employee.php');
// kung anong file.php mag ffall ung user pag valid ung log in procedures nya.
}
else {
$message = "Invalid username or password";
}
} else {
$message = "";
}
echo "$message";
?>
<?PHP print $message;?>