Ask a question to judge the $_post pass parameter, cannot fetch the number

Source: Internet
Author: User
There is a new/modified feature on the Web page, a
if (Isset ($_post[' id ')) && isset ($_post[' uname ']) &&!empty ($_post[' id ')) &&!empty ($_post[') Uname '])) {
$id = $_post[' id '];
$uname = $_post[' uname ');
if ($pid ==0) {
New User---------------------If the value passed in is 0, the statement is not executed, and if the value is 00, the statement is executed.
}else{
Modify User
}
}
Cleanparameters ($_get);
Cleanparameters ($_post);
?>


Reply to discussion (solution)

Because
So
if (Isset ($_post[' id ')) && isset ($_post[' uname ']) &&!empty ($_post[' id ')) &&!empty ($_post[') Uname ']))
Because the part of the set broken is not established, will not enter the branch

Because
So
if (Isset ($_post[' id ')) && isset ($_post[' uname ']) &&!empty ($_post[' id ')) &&!empty ($_post[') Uname ']))
Because the part of the set broken is not established, will not enter the branch


Why would id=0 be considered empty? 0 at least it's a value! It's not empty.

$a = ' 0 '; Var_dump (! empty ($a));//bool (false)

You can see the description of empty

Rules are for you to obey, maybe a little passable.

if ($pid ==0) {There is also a problem here, $pid no value, $pid = $_post[' id ')

Empty? Checks if a variable is empty
BOOL Empty (mixed $var)
That's the way the rules are.
If Var is a non-null or nonzero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, Array (), Var $var; and objects that do not have any properties will be considered empty and return TRUE if Var is empty.

If you want to determine that 0 is non-null, you can write this.
if (Isset ($_post[' id ') && isset ($_post[' uname ']) &&! (Empty ($_post[' id ') && $_post[' id ']!=0) &&!empty ($_post[' uname '])) {

Determine if a form submission requires only
if ($_server[' request_method '] = = "POST")
A little bit more simple is
if ($_post)

The submitted data is always a string, so determine if the ID control is 0
if ($_post[' id ') = = = ' 0 ')
Can

Of course
if ($_post[' id ') = = ' 0 ')
if (Empty ($_post[' id ')))
It's all right, but you can't tell whether it's a blank or a 0.

if ($_post) {    $id = $_post[' id '];    $uname = $_post[' uname ');    if ($id ==0) {      New user---------------------If the value passed in is 0, the statement is not executed, and if the value is 00, the statement is executed.    }else{      Modify user    }}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.