Effect of submitting an empty form on isset

Source: Internet
Author: User

The following sample code is used to explain:

1. When loading the page for the first time, because the form is not submitted, $ _ post is an empty array. At this time, $ _ post ['name'] is null, that is, the variable $ name has not been set,

Isset determines that isset ($ name) is false;

2. When the page has been loaded but no input is made at the input username, when the form is submitted, $ _ post ['name'] is an empty string, that is, the variable $ name has been set;

Isset determines that isset ($ name) is true;

Conclusion: 1. When an empty form is submitted, $ _ post ['variable name'] submits a null string, but it is definitely not null. When isset is used for determination, the result is true, so in some cases,

You must use isset [$ name] = ''to determine whether to use it;

2. The form passing effect in get mode is the same as that in post mode. You should also note that.

Example:

<? PHP
$ Name = $ _ post ['name'];
Echo '<br> ';
If (isset ($ name )){
Echo $ name. "<br> ";
Echo "if the proof \ $ name is empty <br> ";
}
Else {
Echo $ name. "<br> ";
Echo "if the proof \ $ name is null is displayed here <br> ";
}
?>
<HTML>
<Head>
<Title> DSAF </title>
</Head>
<Body>
<Form method = "Post" Action = "isset. php">
<P> enter the User name: </P>
<Input type = "text" name = "name">
<Br>
<Input type = "Submit" value = "Submit">
</Form>
</Body>
</Html>

Welcome to the station

Http://www.hiwhat.com

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.