I have a Login-page designed (in PHP) and working fine.
If the user’s credentials are verified, he is re-directed to the website’s main-page.
However, if he inputs the wrong credentials (username and/or password), he gets an error message saying : “the username or password is incorrect. Please try again”……….or some such thing.
This is also working fine…….except the styling. When my php codes “echoes” the error message, it is displayed at [B]the very top, left corner of the screen.
I would like to display the error message either within the log-in box itself, or at least directly above the log-in box.
Here is the PHP code for the login process :
[code=php]if(!empty($_POST[‘login’])) {
$query = mysqli_query($conn,(“SELECT * FROM my_table where login = ‘$_POST[login]’ AND password = ‘$_POST[password]'”))
or die(mysqli_error($conn));
$row = mysqli_fetch_array($query);
if(!empty($row[‘login’]) AND !empty($row[‘password’])) {
$_SESSION[‘login’] = $row[‘login’];
$_SESSION[‘password’] = $row[‘password’];
echo “LOGIN SUCCESSFULL. Re-directing……………”; }
else {
echo “Sorry. Wrong username and/or password.”;
}
}
?>
And here is my log-in box (HTML) :
[code=html]
<body>
<div id=”Sign-In”>
<fieldset style=”width:30px”><legend><b>Please log in :</b></legend>
<form method=”POST” action=”login.php”>
Username <br><input type=”text” name=”login” size=”40″ required><br>
Password <br><input type=”password” name=”password” size=”40″ required>
<br>
<br>
<input id=”button” type=”submit” name=”submit” value=”Log In”>
<input id=”button” value=”Cancel” onclick=”location.href=’xxxxxxxxxxxxx'”>
<br>
</form>
</fieldset>
</div>
</body>
When login is successful, the user is re-directed to another page;
If not, that error message is displayed : [B]echo “Sorry. Wrong username and/or password.”;
However, I would like the message displayed in alignment with the login-box itself
I’ve tried using all forms of CSS styling, but the message keeps getting displayed “[B]outside
The only other option I can think of is to re-direct the user to another page if login is unsuccessful. But, this is a nuisance for the user.