嘿,我遇到了一个可能很容易解决的问题,但我似乎无法找到任何问题。
我有一张表格:
<form action="<?php echo $_SERVER['self']; ?>" method="post">
First Name: <input name="firstnamepass" type="text" size="35" /><br />
Surname: <input name="surnamepass" type="text" size="35" /><br />
Email: <input name="emailpass" type="text" size="35" /><br />
<input type="submit" value="Search Member" />
现在我有PHP获取帖子数据:
if(isset($_POST['firstnamepass']))
echo "surname is set <br />";
if(isset($_POST['surnamepass']))
echo "surname is set <br />";
if(isset($_POST['emailpass']))
echo "email is set <br />";
问题是,即使我没有为它设置值,一切似乎都已设置。有任何想法吗?有什么方法吗?
感谢您的帮助。
答案 0 :(得分:2)
使用空函数 - http://php.net/manual/en/function.empty.php
if(!empty($_POST['firstnamepass']))
echo "surname is set <br />";
if(!empty($_POST['surnamepass']))
echo "surname is set <br />";
if(!empty($_POST['emailpass']))
echo "email is set <br />";
答案 1 :(得分:1)
您应该测试长度,或测试变量是否为空。
if(strlen($_POST['firstnamepass']) > 0)
echo "OK";
if(!empty($_POST['firstnamepass']))
echo "OK";
答案 2 :(得分:0)