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