Implementation of added functions of PHP development news management system

To implement the modification function, let’s look at the following flow chart

adds.png

Let’s look at the code for the following added page: news.php

      
标题:

内容:

As above As you can see from the code, the form is submitted to the addnews.php file

Let’s look at the code of the addnews.php file below:

First we need to connect to the database and add to get information from the form Add it to the database, so we need to connect to the database

The code is as follows:

header("Content-type: text/html; charset=utf-8"); //Set encoding
$con =@mysql_connect("localhost","root","root") or die("Database connection failed");
mysql_select_db('news') or die("Specified The database cannot be opened");
mysql_query("set names utf8");//Set the character set of the database

Then get the form information:

$title = $_POST['title'];
$content = $_POST['content'];
$messtime = time();

Before adding to the database , we first need to judge whether the title and content of the text box are empty. If they are empty, we will give a prompt. The code is as follows:

if(empty($title)){
Echo "& lt; script & gt; alert ('Please enter the title'); History.go (-1); & lt;/script & gt; ;script>alert('Please enter content');history.go(-1);";
}

We can only do this when the content is not empty Add content to the database, the code is as follows:

$sql = "insert into new (title,content,messtime) values('$title','$content','$messtime')";

$result =mysql_query($sql);if($result){
echo ""; }elseif(empty($content)){ echo ""; }else{ $sql = "insert into new (title,content,messtime) values('$title','$content','$messtime')"; $result =mysql_query($sql); if($result){ echo ""; }else{ echo ""; } } ?>

Continuing Learning
||
alert('请输入标题');history.go(-1);"; }elseif(empty($content)){ echo ""; }else{ $sql = "insert into new (title,content,messtime) values('$title','$content','$messtime')"; $result =mysql_query($sql); if($result){ echo ""; }else{ echo ""; } } ?>
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!