Php _ POST gets the value. how to verify if the value does not exist

Source: Internet
Author: User
Php _ POST to obtain the value. If no value exists, how to verify & lt; html & gt; & lt; head & gt; & lt; title & gt; test php & lt; /title & gt; & lt;/head & gt; & lt; body & gt; & lt; formaction = & quot; test. in php & quot; php, _ POST gets the value. how to verify if no value exists?


Test php





$ Name = "";
If (! Empty ($ _ POST ["name"])
{
$ Name = $ _ POST ["name"];
}
Print $ name;
?>

If an error is reported during running, no $ _ POST ["name"] value is displayed at the beginning. how can I verify whether there is a $ _ POST ["name"] value.
If the name value is submitted, print the value. if it is not, print ""

------ Solution --------------------
What is the error? You can also. Use isset.
------ Solution --------------------
Change test. php:

If (isset ($ _ POST )){
$ Name = "";
If (! Empty ($ _ POST ["name"])
{
$ Name = $ _ POST ["name"];
}
Print $ name;
} Else {
Echo "$ _ POST not Set! ";
}

?>
------ Solution --------------------
Curious, what are the errors returned by this code?
------ Solution --------------------
The error level is too high. if you close the error prompt, it will not be reported. This is available in the production environment, and the development is still rigorous. it is better to develop a good habit of verification.

We recommend that you use the isset () function mentioned above to verify whether the value exists.

For example, if you want to know whether name value submission exists, you can:

PHP code
If (isset ($ _ POST ['name']) |! Empty ($ _ POST ['name']) {echo $ _ POST ['name']; // The value exists and is not empty.} else {echo ""; // The value does not exist or is empty. print "";}

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.