PHP表单验证

exit()停止后续脚本执行

单个字段空白判定

if(empty($_POST['last_name']))
{
echo "You did not enter your last name.
Last name is required.<br />\n";
redisplay the form;
exit();
}
echo "Welcome to the Members Only club.
You may select from the menu below.\n";
display the menu;

所有字段空白判定

foreach($_POST as $value)
{
if($value == "")
{
echo "You have not filled in all the fields.\n";
redisplay the form;
exit();
}
}
echo "Welcome";

除之外都空白判定

foreach($_POST as $field => $value)
{
if($value == "")
{
if($field != "fax" and $field != "middle_name")
{
echo "You have not filled in $field\n";
display the form;
exit();
}
}
}
echo "Welcome";
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容