php noobs question

0 votes
109 views
asked May 16 in General by ram
I am trying to submit and get values from a form. There, it checks if the input mail is filled. Problem is, I'm seeing it submitted everytime even if value is not filled. 

Please see below codes.

<form name="testform" method="post" action="checkdata.php"> 
<input type="text" name="emailid"/> <br />
<input type="password" name="password"/><br />
<input type="submit"  value="submit"/>
</form>

and on checkdata.php
if (isset($_POST["mailid"])) {
    echo "Yes, mailid was submitted";    
}else{  
    echo "No, mailid was not submitted";
}
What am I doing wrong here? 

1 Answer

0 votes
answered May 16 by anonymous

When you submit that form, $_POST is always set, same in case of $_POST["mailid"]

The variable is set, but it is blank. So you need to check if it is blank also.

if (isset($_POST["mailid"]) && !empty($_POST["mailid"])) {
    echo "Yes, mailid was submitted";
}else{  
    echo "No, mailid was not submitted";
}

Related questions

0 votes
1 answer 275 views
asked May 26, 2016 in General by Cyan
+2 votes
1 answer 234 views
+1 vote
1 answer 241 views
+2 votes
1 answer 157 views
asked Feb 9 in General by Marc Lentin
0 votes
2 answers 247 views
asked Nov 24, 2016 in General by srinivasulu_yagnam (200 points)
...