Why is the code I wrote in php not displayed in a browser? & lt ;? Php & nbsp; if (isset ($ _ POST [Submit]) & amp; $ _ POST [Submit] & quot; Login & quot;) {& nbsp; $ user $ _ POST [user]; $ pass $ _ POST [pass]; if (why is this code written on php not displayed in the browser?
If (isset ($ _ POST ['submit ']) & $ _ POST ['submit'] = "login "){
$ User = $ _ POST ['user'];
$ Pass = $ _ POST ['pass'];
If (empty ($ user) | empty ($ pass )){
Echo "script" alert ('user name and password cannot be blank '); script ";
}
Else {
Echo "input username: $ user password: $ pass ";
}
}
?>
The result of running on the browser is blank
------ Solution --------------------
This condition indicates that if (isset ($ _ POST ['submit ']) & $ _ POST ['submit'] = "login") is not true, so it's blank. you can check it in the table. The name of the button is not name = "login ",
If the $ _ POST ['submit '] = "login" condition is not true, change them to the same one,
In addition, the method in form must be submitted using the post method, that is, method = "post"
Yes.
In the form
Write in php as follows:
If (isset ($ _ POST ['login']) & $ _ POST ['login'] = "login "){
$ User = $ _ POST ['user'];
$ Pass = $ _ POST ['pass'];
If (empty ($ user) | empty ($ pass )){
Echo "script" alert ('user name and password cannot be blank '); script ";
}
Else {
Echo "input username: $ user password: $ pass ";
}
}
Else {
Echo "the form has not been submitted ";
}
?>
------ Solution --------------------
Discussion
This condition indicates that if (isset ($ _ POST ['submit ']) & $ _ POST ['submit'] = "login") is not true, so it's blank. you can check it in the table. The name of the button is not name = "login ",
If the $ _ POST ['submit '] = "login" condition is not true, change them to the same one,
In addition, the method in form ......
------ Solution --------------------
Refer to the PHP Manual: language reference-> variables other than PHP
HTML code
------ Solution --------------------
$ _ POST ['submit '] = "login"
The value passed in the form (Chinese) is encoded. Of course, the verification fails!
If you change to English
Or you can remove this one, as shown in the following figure. If this key value exists, it is executed.
PHP code
------ Solution --------------------
If (isset ($ _ POST ['submit ']) & $ _ POST ['submit'] = "login "){
$ User = $ _ POST ['user'];
$ Pass = $ _ POST ['pass'];
If (empty ($ user) | empty ($ pass )){
Echo "script" alert ('user name and password cannot be blank '); script ";
} // Here is a Braces
} Else {
Echo "input username: $ user password: $ pass ";
}
// This braces are too many}
?>