Use a text file to create a message board prompt (below)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.