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.

211

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 submitPOST is set.

if (isset($_POST['submit']) && isset($_POST['username']) && $_POST['password'] == "")  {
    echo "Please enter your password.";
}
178

Answer

Solution:

if (isset($_POST['username']) && ($_POST['password'] == ""))  {
    echo "Please enter your password.";
}
346

Answer

Solution:

Below your form enter the following:

if ((isset($_POST['username'])) == true && (isset($_POST['password'])) == false ){
   echo "please enter your password";
}

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:

if ((isset($_POST['value'])) == true && (isset($_POST['value2'])) == false{
   echo "error message!";
}

People are also looking for solutions to the problem: php - Unexpected end of JSON input at JSON.parse

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.