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 );