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

6
  • So check username then. Commented Jan 18, 2020 at 11:23
  • @u_mulder yes it works, but i want to do it with isset, this is a simple case, am having a huge form, and i want to check if(isset($_POST["submit"])) Commented Jan 18, 2020 at 11:27
  • $_POST["submit"] is a button, it is always set as you press this button to submit. Commented Jan 18, 2020 at 11:33
  • it just does not make anysense i've seen lots of tutos using the same function? even using just $_POST will always give me that its filled Commented Jan 18, 2020 at 11:35
  • So this tutos check that someone is trying to submit the form, they not check that form is empty or not filled. Commented Jan 18, 2020 at 11:36

1 Answer 1

0

Use !empty() instead of isset();

<?php if (!empty($_POST["username"]) && !empty($_POST["submit"])) { echo "filled"; } else { echo "not filled"; } 
Sign up to request clarification or add additional context in comments.

Comments