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

2020-10-09 0 192

新闻发布系统

1. 系统简介

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

2.数据库设计

-- 数据库: `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 ;

首页

<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>

首页效果图

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

新建新闻

<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+mysql实现新闻发布系统的开发

新建新闻PHP

<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>

查询新闻

<title>搜索新闻</title>
</head>

<body>
<form action=\"ssxw.php\" method=\"post\">
<input type=\"text\" name=\"ssxw\" />
<input type=\"submit\" value=\"搜索\" />
</form>
</body>

查询新闻效果图

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

查询新闻PHP

<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>

查询新闻效果图

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

注意:
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新闻发布系统内容请搜索自学编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持自学编程网!

遇见资源网 PHP 基于PHP+mysql实现新闻发布系统的开发 http://www.ox520.com/22578.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务