PHP development of simple news release system news release page PHP code

In this section, we use the background PHP code to add data to the database and display it on the news list page

Main idea:

Fill in the news in the form The content includes: title, author, content, other field id, release time created_at, modification time updated_at. The content is completed by the server. Of course, you have to write the program yourself, but you don’t have to do it manually. After submitting the form, use MySQL statements to add them to the database.

The release time created_at and modification time updated_at will be used in the example. We will directly set them to the current release time and modification time.

You need to use the date() function: format the timestamp into a more readable date and time.

You can get simple dates and times

date("Y-m-d") means getting the year-month-day

date("H:i:s" ) means getting hours-minutes-seconds

Because we all use the Eastern Hemisphere time zone, here we use date_default_timezone_set('Asia/Shanghai') to set the time zone to the time zone of Shanghai.

1605.png

Of course we still need to connect to the database first. Here we create a database named test.

We use the POST method to obtain data

Use insert into(): add data to the database table (create a table named new),

Show the complete code publish.php file:

alert('新闻发布成功');window.location.href='list.php'"; //发布成功跳转到新闻列表页list.php }else{ echo ""; } ?>


Continuing Learning
||
alert('新闻发布成功');window.location.href='list.php'"; //发布成功跳转到新闻列表页list.php }else{ echo ""; } ?>
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!