Php uses code to input a text box and a button to the text box. when the button is pressed, make a judgment first. if the text box is blank (the text box content is admin ), if the text box content is not the same as the input content, how do I write this code?
If ($ _ POST ['sub']) {
// Obtain the content of the text box
$ Content = $ _ POST ['content'];
If ($ content = ""){
If the text box is null, the text box content is equal to "admin"
}
}
Reply to discussion (solution)
Error message: Parse error: syntax error, unexpected '}' in D: \ WWW \ login. php on line 8
My code is:
Demo
If you have to use php for judgment:
$ Content = (isset (trim ($ _ POST ['content']) & trim ($ _ POST ['content'])! = '')? Trim ($ _ POST ['content']): 'admin ';
?>
Or set it directly in html using js.
I'm also drunk. php should end with a semicolon and certainly report an error.
HELLO
Error message: Parse error: syntax error, unexpected '}' in D: \ WWW \ login. php on line 8
My code is:
Demo
Haha, I forgot a semicolon by mistake.
HELLO
Your code is to display the value to the echo $ aval; page, I want him to display the content text box content, Display to text box using js
Error message: Parse error: syntax error, unexpected '}' in D: \ WWW \ login. php on line 8
My code is:
Demo
Haha, I forgot a semicolon by mistake.
No, it is added. the system prompts an error after the minute is finished, but it does not respond after the press, and there is no admin in the text box.
Display to text box using js
Js I know, I want to use php to implement I didn't understand what you meant yesterday. today I basically understood what you meant. You actually want to use php to do what js should do. this is redundant. Php is a server-side script and cannot operate on dom. if you have to do so, you have to have a database or set a session. in this way, you can use a cool tool. Php assigns values to text mostly to modify data. Because php interacts with data through webpage requests, it needs to refresh the page (of course, you can also skip the new page, so you need to use ajax background without refreshing the new interaction), so you don't need to use js to use session? Will the session be destroyed after it is used up? Why do we do this?
If ($ _ POST ['sub']) {
// Obtain the content of the text box
$ Content = trim ($ _ POST ['content']);
If ($ content = ""){
$ Content = 'admin'
}
}
?>
Demo
Is that okay? But what does this mean?
I didn't understand what you meant yesterday. today I basically understood what you meant. You actually want to use php to do what js should do. this is redundant. Php is a server-side script and cannot operate on dom. if you have to do so, you have to have a database or set a session. in this way, you can use a cool tool. Php assigns values to text mostly to modify data. Because php interacts with data through webpage requests, it needs to refresh the page (of course, you can also skip the new page, so you need to use ajax background without refreshing the new interaction), so you don't need to use js to use session? Will the session be destroyed after it is used up? Why do we do this?
I have a database, and I use session. that's what I mean. it's okay if you just want to kill pigs and kill chickens. What should I do? Then you can set the value at the time of submission and assign it to the text box. you can destroy the session as needed.
If (isset ($ _ POST ['content']) & trim ($ _ POST ['content']) {
$ Content = trim ($ _ POST ['content']);
$ _ SESSION ['content'] = $ content;
}
// This session will be destroyed after you run out. it is not estimated that the session will not be destroyed, as long as it does not repeat the name.
?>
Demo
This should be fine. you can test it. The basic idea is as follows. if the test fails, check whether there is a semicolon or something missing.
Then you can set the value at the time of submission and assign it to the text box. you can destroy the session as needed.
If (isset ($ _ POST ['content']) & trim ($ _ POST ['content']) {
$ Content = trim ($ _ POST ['content']);
$ _ SESSION ['content'] = $ content;
}
// This session will be destroyed after you run out. it is not estimated that the session will not be destroyed, as long as it does not repeat the name.
?>
Demo
This should be fine. you can test it. The basic idea is as follows. if the test fails, check whether there is a semicolon or something missing.
Then you can set the value at the time of submission and assign it to the text box. you can destroy the session as needed.
If (isset ($ _ POST ['content']) & trim ($ _ POST ['content']) {
$ Content = trim ($ _ POST ['content']);
$ _ SESSION ['content'] = $ content;
}
// This session will be destroyed after you run out. it is not estimated that the session will not be destroyed, as long as it does not repeat the name.
?>
Demo
This should be fine. you can test it. The basic idea is as follows. if the test fails, check whether there is a semicolon or something missing.
There is something wrong with php above. you want to set it to admin if the text box is empty, right?
$ Content = trim ($ _ POST ['content']);
If ($ content = ''){
$ Content = 'admin ';
}
$ _ SESSION ['content'] = $ content;
?>
Then you can set the value at the time of submission and assign it to the text box. you can destroy the session as needed.
If (isset ($ _ POST ['content']) & trim ($ _ POST ['content']) {
$ Content = trim ($ _ POST ['content']);
$ _ SESSION ['content'] = $ content;
}
// This session will be destroyed after you run out. it is not estimated that the session will not be destroyed, as long as it does not repeat the name.
?>
Demo
This should be fine. you can test it. The basic idea is as follows. if the test fails, check whether there is a semicolon or something missing.
Then you can set the value at the time of submission and assign it to the text box. you can destroy the session as needed.
If (isset ($ _ POST ['content']) & trim ($ _ POST ['content']) {
$ Content = trim ($ _ POST ['content']);
$ _ SESSION ['content'] = $ content;
}
// This session will be destroyed after you run out. it is not estimated that the session will not be destroyed, as long as it does not repeat the name.
?>
Demo
This should be fine. you can test it. The basic idea is as follows. if the test fails, check whether there is a semicolon or something missing.
There is something wrong with php above. you want to set it to admin if the text box is empty, right?
$ Content = trim ($ _ POST ['content']);
If ($ content = ''){
$ Content = 'admin ';
}
$ _ SESSION ['content'] = $ content;
?>
Demo
If the text box is empty, click the button. the text box does not show admin.
Then you can set the value at the time of submission and assign it to the text box. you can destroy the session as needed.
If (isset ($ _ POST ['content']) & trim ($ _ POST ['content']) {
$ Content = trim ($ _ POST ['content']);
$ _ SESSION ['content'] = $ content;
}
// This session will be destroyed after you run out. it is not estimated that the session will not be destroyed, as long as it does not repeat the name.
?>
Demo
This should be fine. you can test it. The basic idea is as follows. if the test fails, check whether there is a semicolon or something missing.
Then you can set the value at the time of submission and assign it to the text box. you can destroy the session as needed.
If (isset ($ _ POST ['content']) & trim ($ _ POST ['content']) {
$ Content = trim ($ _ POST ['content']);
$ _ SESSION ['content'] = $ content;
}
// This session will be destroyed after you run out. it is not estimated that the session will not be destroyed, as long as it does not repeat the name.
?>
Demo
This should be fine. you can test it. The basic idea is as follows. if the test fails, check whether there is a semicolon or something missing.
There is something wrong with php above. you want to set it to admin if the text box is empty, right?
$ Content = trim ($ _ POST ['content']);
If ($ content = ''){
$ Content = 'admin ';
}
$ _ SESSION ['content'] = $ content;
?>
Demo
If the text box is empty, click the button. the text box does not show admin.
Dizzy, Big Brother. you can test it yourself. I'll give you a thought. you have to modify it. didn't you find no href in your form? Where can I handle the submission? The following code is correct. I have tested it. remember to change the href address of the form to your own.
If (isset ($ _ POST ['content']) {
$ Content = trim ($ _ POST ['content']);
If ($ content = ''){
$ Content = 'admin ';
}
$ _ SESSION ['content'] = $ content;
}
?>
Test