基于PHP+mysql实现新闻发布系统的开发

吾爱主题 阅读:156 2021-10-21 12:52:00 评论:0

新闻发布系统

1. 系统简介

    一个简单的新闻系统,包含了四个功能,增删改查,利用php语言,结合了mysql数据库,开发工具用的是dreamweaver。

2.数据库设计

?
1 2 3 4 5 6 7 8 9 10 11 12 13 -- 数据库: `newsdb` create database if not exists `newsdb` default character set utf8 collate utf8_general_ci; use `newsdb`; -- 表的结构 `news` create table if not exists `news` (   `id` int(9) not null auto_increment,   `title` varchar(50) not null,   `keywords` varchar(50) not null,   `author` varchar(16) not null,   `addtime` datetime not null,   `content` text not null,   primary key (`id`)    ) engine=innodb default charset=utf8 auto_increment=4 ;

首页

?
1 2 3 4 5 6 7 <title>新闻首页</title> </head>   <body bgcolor= "#cc6666" > <h1 align= "center" >新闻首页</h1> <h3 align= "center" ><a href= "action.html" rel= "external nofollow" >新建新闻</a>&nbsp;&nbsp;修改新闻&nbsp; &nbsp; 删除新闻&nbsp;&nbsp;<a href= "ssxw.html" rel= "external nofollow" >搜索新闻</a></h3> </body>

首页效果图

新建新闻

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 <title>插入新闻</title> </head>   <body> <form action= "adds.php" method= "post" > <h3 align= "center" >插入新闻</h3> <table width= "300" align= "center" border= "2" > <tr> <td>标题</td> <td><input type= "text" name= "title" /></td> </tr> <tr> <td>关键字</td> <td><input type= "text" name= "keywords" /></td> </tr> <tr> <td>作者</td> <td><input type= "text" name= "author" /></td> </tr> <tr> <td>内容</td> <td><input type= "text" name= "content" /></td> </tr> <tr > <td colspan= "2" align= "center" ><input type= "submit" value= "提交" /></td> </tr> </table> </form> </body>

新建新闻效果图

新建新闻php

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 <title>动态</title> </head>   <body> <?php //加载数据库 //include("mysql.php"); //连接数据库 mysql_connect( "localhost" , "root" , "" ) or die ( "连接失败" ); //设置编码格式 mysql_query( "set names utf-8" ); //选择数据库 mysql_query( "use newsdb" ) or die ( "选择失败" ); //获取输入文本 $bt = $_post [ 'title' ]; $gzj = $_post [ 'keywords' ]; $zz = $_post [ 'author' ]; $nn = $_post [ 'content' ]; //获取系统时间 /*改时区*/ date_default_timezone_set( 'prc' ); $time = date ( 'y-m-d h:i:s' ); //加入数据 $mysql = "insert into news values(null,'$bt','$gjz','$zz','$time','$nn')" ; $aa =mysql_query( $mysql ); //判断是否插入 if ( $aa ){    echo "添加成功" ;}    else { echo "添加失败" ;}     ?> </body>

查询新闻

?
1 2 3 4 5 6 7 8 9 <title>搜索新闻</title> </head>   <body> <form action= "ssxw.php" method= "post" > <input type= "text" name= "ssxw" /> <input type= "submit" value= "搜索" /> </form> </body>

查询新闻效果图

查询新闻php

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 <title>搜索新闻</title> </head> <body> <table width= "500" border= "2" > <tr> <th colspan= "col" >id</th> <th colspan= "col" >标题</th> <th colspan= "col" >关键字</th> <th colspan= "col" >作者</th> <th colspan= "col" >时间</th> <th colspan= "col" >内容</th> </tr> <?php //载入数据库 include ( "mysql.php" ); //获取输入的标题 $ssxw = $_post [ 'ssxw' ]; //利用 查询语句 $sql = "select * from news where title like '%$ssxw%'" ; //利用索引数组 $cx =mysql_query( $sql ); //遍历出来 while ( $sy =mysql_fetch_row( $cx )){    echo "<tr>" ;    echo "<td>$sy[0]</td>" ;    echo "<td>$sy[1]</td>" ;    echo "<td>$sy[2]</td>" ;    echo "<td>$sy[3]</td>" ;    echo "<td>$sy[4]</td>" ;    echo "<td>$sy[5]</td>" ;    echo "</tr>" ; } echo "<a href='index.html'>新闻首页</a>" ; ?> </table> </body>

查询新闻效果图

 

注意:
1.连接数据库
mysql_connect(“localhost”,”root”,”“) or die(“连接失败”);
2.设置编码格式
mysql_query(“set names utf-8”);
3.选择数据库
mysql_query(“use newsdb”) or die(“选择失败”);       

在这里先做出增加和查询两个功能,其他功能持续更新中。。。。。。
期待与你一起学习。

到此这篇关于基于php+mysql实现新闻发布系统的开发的文章就介绍到这了,更多相关php+mysql新闻发布系统内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/qq_40477146/article/details/80632073

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容