Managing Your messages in text files is not as convenient as in the database. Next we will try to achieve this effect!
When outputting data, we use arrays to store data. Therefore, we can easily assign an sequence number to each group of data in order and operate on the sequence number, we can easily modify the data!
$ Date [0] is the first line in the text file. When we output the data, the allocation sequence number is 0.
The output has the following effect:
<A href = "modify. php? Id = 0'> modify message </a>
Let's customize modify. php.
<? PHP
If ($ ID! = ""){
$ Date = file ("TXT/mytxt.txt ");
$ STR = explode ("&", $ date [0])
?>
<Form method = "Post" Action = "Modify. php" onsubmit = "Return check ()">
<Input type = "text" name = "tech1" value = <? PHP echo $ STR [0];? >>
<Input type = "text" name = "tech2" value = <? PHP echo $ STR [1];? >>
<Input type = "text" name = "tech3" value = <? PHP echo $ STR [2];? >>
<Input type = "Submit" name = "Submit" value = "Submit">
</Form>
<? PHP
} Else {
$ STR = $ tech1. "&". $ tech2. "&". $ tech3 ....
If ($ Str! = ""){
// Write the modified data back to a text file!
}
}?>
In this process, note that the value of $ ID is not lost. When writing back data, read the value in the text into $ date, and then $ date [$ id] = $ STR;
$ Fp = fopen ("TXT/mytxt.txt", "W ");
Fwrite ($ FP, $ date );
Fclose ($ FP );