开发者

Problems with $_POST values

开发者 https://www.devze.com 2023-04-12 23:37 出处:网络
Hey i got a problem that might be easily solved, but i can\'t seem to find anything on it. I have a form:

Hey i got a problem that might be easily solved, but i can't seem to find anything on it.

I have a form:

<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" /> 

Now i have PHP getting the post data:

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 />";

Problem is, everything seems to be set even if i haven't set a value for it. Any ideas? Any way around it?

thanks for the h开发者_Python百科elp.


Use empty function instead - 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 />";


You should test the length instead, or test if the variable is not empty.

if(strlen($_POST['firstnamepass']) > 0)
    echo "OK";
if(!empty($_POST['firstnamepass']))
    echo "OK";


Use if !empty();. To determine if the values are not empty.

Also Use strlen(); to determine the length of the strings.

0

精彩评论

暂无评论...
验证码 换一张
取 消