PHP return value acquisition
$ Yjj = key ($ _ GET );
$ Logi = file ("./data/list.txt", FILE_IGNORE_NEW_LINES );
Foreach ($ Logi as $ Key => $ Val ){
List ($ num, $ title) = explode ("|", $ Val );
If ($ title = $ yjj)
{
$ Comment = $ _ POST ['txt '];
$ Filename = "Item" .({num}.'.txt ';
$ File = fopen ('./data/comments/'. $ filename, 'A ');
Fwrite ($ file, $ Comment );
Fclose ($ file );
}
}
?>
$ Yjj = key ($ _ GET) is the value returned from the previous page. I want to set a text box on this page, obtain the input content as $ Comment = $ _ POST ['txt ']. However, if the input content fails to be obtained multiple times, the value cannot be obtained. please advise
Reply to discussion (solution)
Remove the if ($ title = $ yjj) judgment first. It is estimated that there is a problem with the judgment here, and it is not included in the if. Second, pay attention to the write permission of the folder.
Method = "post" double quotation marks.
Print them one by one
Remove the if ($ title = $ yjj) judgment first. It is estimated that there is a problem with the judgment here, and it is not included in the if. Second, pay attention to the write permission of the folder.
Method = "post" double quotation marks.
The txt file can be created. the num in the txt name is also correct, that is, all the text is empty. I don't know what's going on.
Print $ Comment directly to see echo $ Comment. Add fflush ($ file) before fclose );
Print them one by one
It seems that there is a problem with this sentence.
$ Comment = $ _ POST ['txt '];
Because if I change to $ Comment = "yyyyyyy" or something like that
Print $ Comment directly to see echo $ Comment. Add fflush ($ file) before fclose );
If it is placed in if, it is null to print out... It must be placed outside the if clause, but the condition can be used.
Print_r ($ _ POST );
The pasted code is the content of comment01.php, right?
If yes, there is a conflict.
1. $ yjj = key ($ _ GET); is used to obtain the parameters submitted by the get method in another post.
The code here does not produce get parameters.
Therefore, $ yjj = key ($ _ GET); the value is only available when the first entry is made.
Your operations are performed when if ($ title = $ yjj) is set up, so it is impossible to perform operations as long as it is not the first entry.
2. when you enter the file for the first time, $ Comment = $ _ POST ['txt ']; is empty because the get method is used. although the file is written, the value is null.
After the form is filled in and submitted, it enters the 1 state and does not execute the Write file.
The pasted code is the content of comment01.php, right?
If yes, there is a conflict.
1. $ yjj = key ($ _ GET); is used to obtain the parameters submitted by the get method in another post.
The code here does not produce get parameters.
Therefore, $ yjj = key ($ _ GET); the value is only available when the first entry is made.
Your operations are performed when if ($ title = $ yjj) is set up, so as long as it is not the first ......
I have always wanted to separate $ yjj = key ($ _ GET) from $ Comment = $ _ POST ['txt '], but I don't know how to do it, if you create another page, how can we return both $ yjj and $ Comment2 values?
Put the $ yjj value in the form and submit it together.
Put the $ yjj value in the form and submit it together.
$ Logi = file ("./data/list.txt", FILE_IGNORE_NEW_LINES );
Foreach ($ Logi as $ Key => $ Val ){
List ($ num, $ title) = explode ("|", $ Val );
If ($ num ){
Echo $ title;
?>
}
}
?>
This is my previous page. how can I get the return values of the button and the return values of the form at the same time, or add another page? I think it's a long time, and it's sad to be a newbie.