php - If username is set and password is not, display me an error message
875
<div class="form">
<h1>Log In</h1>
<form action="" method="post" name="login">
<input type="text" name="username" placeholder="username" required />
<input type="password" name="password" placeholder="password" required />
<input name="submit" type="submit" value="Login" />
</form>
<?php
if (isset($_POST['username']) && !isset($_POST['password'])) {
echo "Please enter your password.";
}?>
I just want to display an error message IF username IS set and password field is not filled with any character after click on "submit", this is how I tried but now working for me.
Answer
Solution:
In your form you are missing an action. Inside the action attribute put the same URL that you did below. Also, you should check if the submit
POST
is set.Answer
Solution:
Answer
Solution:
Below your form enter the following:
This means that if the username is set and the password is NOT set it will display the error message of: "please enter you password". You can change this and use it as a template: