PHP Add and modify data in the same form 2_PHP tutorial

WBOY
Release: 2016-07-13 10:28:42
Original
855 people have browsed it

Okay, actually I don’t care about the number of visits, but the number of visits today is more than the one I posted last year.

I am still a little surprised. As a loser who works in technology. No, I don’t consider myself a loser. I think programming is a high-level profession. Although it is very tiring, it can really make you happy every day. Life is fulfilling.

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

Today we will continue from the previous article, we are just uploading and modifying the article.

What about accessories? If you need to replace accessories during modification, this is really a headache.

I don’t know how everyone achieves it. Let me share my method below.

This is how I implemented it on the page.

I am doing the adding operation in the background.

First we start to receive data, such as the content of title and content. Determine whether the content is empty, and return directly if it is empty.

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

If it fails, we will return directly.

Okay, start the program.

if(IS_POST){

$title = $_POST['title'];

$content = $_POST['content'];

if($title&&$content){

if($_FILES['file']['name'])

//Start processing the submitted attachment.

If successful, you can get the name of our attachment, upload address and other information to see what you need

If failed

Return error.

}

$arr = array(

'title' => $title,

'content' => $content;

'filename' => ///

'filepath' => ///

);

$flag = Perform insertion operation..

if($flag) $str = "Success";

else $str = "Failure";

$this->success("Add".$str,//Jump to the list route.);

}

}//end of post.

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



Now if we want to modify the content.

I thought of a way...

In the page, if there is an attachment, we display the name of the image. If it needs to be modified, we display the file submission box..

I only wrote the key parts...

It’s done...it will look better at the front desk this way...

The backend logic is a bit complicated..

First of all, you have to determine whether there is an attachment. If not, you cannot write a null value into the database. If there is an attachment in the database, but the user has not modified the attachment, if the contents are written uniformly into the database, it will be overwritten. .

Let me tell you my thoughts.

First, determine whether title and content are empty.

If it is not empty, determine whether there is an attachment. If there is an attachment, we will perform a unified receiving operation.

if(IS_POST){

$title = $_POST['title'];

$content = $_POST['content'];

if($title&&$content){

//Here we first define an array..

$data = array();

if($_FILES['file']['name'])

//Start processing the submitted attachment.

If successful, you can get the name of our attachment, upload address and other information to see what you need

If failed

Return error.

Success

$data['filename'] = //File name

$data['filepath'] = //File path.

}

$arr = array(

'title' => $title,

'content' => $content

);

if(!$_POST['id']){

$flag = Perform insertion operation..

$type = "Add";

}else{

$flag = Perform modification operation.

$type = "Modify";

}

if($flag) $str = "Success";

else $str = "Failure";

$this->success($type.$str,//Jump to the list route.);

}

}//end of post.

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



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/780970.htmlTechArticleWell, actually, I don’t value the number of visits, but the number of visits today is more than what I posted last year There is more than one article. I am still a little surprised. As a technical person. No, I don’t...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!