Hi, I'm new to PHP programming, I got stuck when I wanted to display an error message on the same page (index.php). I wanted the error message appears in the (index.php) page instead of (check.php).
I appreciate your help!
index.php: contains a simple login form: username, password and submit button.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="check.php" method='post'>
<input type='text' name='username' placeholder='username'>
<input type='password' name='password' placeholder='password'>
<input id ='register_button' type='submit' value='Login Up'/>
</form>
</body>
</html>
check.php: contains database connection, query and lastly login checking if success prints success and invalid if not.
<?php
include("config.php");
$username = $POST['username'];
$password = $POST['password'];
if($_SERVER["REQUEST_METHOD"] == "POST"){
$query="Select * from admin where username= '$username' and password ='$password'";
if (!($result = mysqli_query($database, $query))){
print("<p>could not execute query!</p>");
die(mysqli_error($database));
}
$row = mysqli_fetch_array($result);
if ($row['username']==$username && $row['password']==$password) {
echo "success";
} else {
echo "invalid";
}
}
?>