0

I want to check if the post if filled or not (post variable empty or not) I'm using "isset", and it just does not seem to work, everytime i submit the form it says filled even when the form is not filled.

PHP code :

<?php
      if (isset($_POST["submit"])) {
          echo "filled";
      } else {
          echo "not filled";
      }
?>

HTML code :

<form method="post">
    <input type="text" name="username" /><br><br>
    <input type="submit" name="submit">
</form>

when i printed $_POST, it says :

[username] => [submit] => Submit

Dharman
  • 30,962
  • 25
  • 85
  • 135
OussamaMater
  • 117
  • 11

1 Answers1

0

Use !empty() instead of isset();

<?php
    if (!empty($_POST["username"]) && !empty($_POST["submit"])) {
        echo "filled";
    } else {
        echo "not filled";
    }
Dharman
  • 30,962
  • 25
  • 85
  • 135
Rahul Wala
  • 44
  • 6