亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

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

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <style type="text/css">
    *{margin:0px;padding:0px;}
    body{background:#ccc;}
    .add{width:450px;height:280px;background:#eee;float:left;}
    .cont{width:500px;height:350px;margin-top:5px;margin-left:5px;}
    form{margin-left:10px;padding-top:30px;}
    .sub{width:100px;height:40px;border:1px solid #ccc;}
    .sub:hover{background:#f90}
    </style>
</head>
<body>
    <div class="add">
        <div class="cont">
            <form method="post" action="addnews.php">
                標(biāo)題:<input type="text" name="title"></br></br>
                內(nèi)容:<textarea cols="50" rows="5" name="content"></textarea></br></br>
                <input type="submit" value="添加" class="sub">
            </form>
        </div>
    </div>
</body>
</html>

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);</script>";
}

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 "<script>alert('Article added successfully');location.href='newlist.php'< /script>";
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? echo "


#The complete source code is as follows:


<?php
    //鏈接數(shù)據(jù)庫
    header("Content-type: text/html; charset=utf-8");//設(shè)置編碼
    $con =@mysql_connect("localhost","root","root") or die("數(shù)據(jù)庫連接失敗");
    mysql_select_db('news') or die("指定的數(shù)據(jù)庫不能打開");
    mysql_query("set names utf8");//設(shè)置數(shù)據(jù)庫的字符集

    //添加操作
    $title = $_POST['title'];
    $content = $_POST['content'];
    $messtime = time();

    if(empty($title)){
        echo "<script>alert('請輸入標(biāo)題');history.go(-1);</script>";
    }elseif(empty($content)){
        echo "<script>alert('請輸入內(nèi)容');history.go(-1);</script>";
    }else{
        $sql = "insert into new (title,content,messtime) values('$title','$content','$messtime')";
        $result =mysql_query($sql);
        if($result){
            echo "<script>alert('添加文章成功');location.href='newlist.php'</script>";
        }else{
            echo "<script>alert('添加文章失敗');history.go(-1);</script>";
        }
    }
?>
Continuing Learning
||
<?php //鏈接數(shù)據(jù)庫 header("Content-type: text/html; charset=utf-8");//設(shè)置編碼 $con =@mysql_connect("localhost","root","root") or die("數(shù)據(jù)庫連接失敗"); mysql_select_db('news') or die("指定的數(shù)據(jù)庫不能打開"); mysql_query("set names utf8");//設(shè)置數(shù)據(jù)庫的字符集 //添加操作 $title = $_POST['title']; $content = $_POST['content']; $messtime = time(); if(empty($title)){ echo "<script>alert('請輸入標(biāo)題');history.go(-1);</script>"; }elseif(empty($content)){ echo "<script>alert('請輸入內(nèi)容');history.go(-1);</script>"; }else{ $sql = "insert into new (title,content,messtime) values('$title','$content','$messtime')"; $result =mysql_query($sql); if($result){ echo "<script>alert('添加文章成功');location.href='newlist.php'</script>"; }else{ echo "<script>alert('添加文章失敗');history.go(-1);</script>"; } } ?>
submitReset Code