Php add and modify data in the same form 2_php tutorial

Source: Internet
Author: User
Php adds and modifies data 2 to the same form. Well, in fact, I don't really care about visits, but today I have more visits than I published in the next year. I was a little surprised. as a technical cool. no, I am not okay. In fact, I don't pay much attention to visits, but today I have more visits than I published in the next year.

I was a little surprised. as a technical cool. no, I don't think I'm a diaosi. I think programming is a great job. although tired, it makes your daily life full.

No matter whether you believe it or not, anyhow I believe it.

Next, let's talk about uploading and modifying simple articles.

If attachments are involved, it is really a headache if attachments need to be changed during modification.

I don't know how it is implemented. let's share my methods.

On the page, I implemented it in this way.

I am adding data in the background.

First, we start to receive data. for example, the content of title and content. determine whether the content is empty. if the content is empty, it is returned directly.

If there is an attachment, we need to determine whether there is an attachment. if there is an attachment, we first move it to the project's uploads folder through the program,

If it fails, we will return it directly.

Okay, go to the program.

If (IS_POST ){

$ Title = $ _ POST ['title'];

$ Content = $ _ POST ['content'];

If ($ title & $ content ){

If ($ _ FILES ['file'] ['name'])

// Start processing the submitted attachments.

If the attachment is successfully uploaded, you can obtain the attachment name, the uploaded address, and other information.

If it fails

An error is returned.

}

$ Arr = array (

'Title' => $ title,

'Content' => $ content;

'Filename' => ///

'Filepath' => ///

);

$ Flag = insert operation ..

If ($ flag) $ str = "successful ";

Else $ str = "failed ";

$ This-> success ("add". $ str, // jump to list route .);

}

} // End of post.

// The following is the template content ....



If we want to modify the content.

I thought of a method ..

On the page, if there is an attachment, we will display the image name. if you need to modify it, we will display the file submission box ..

I only wrote the key part ..

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.