温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

用PHP+mysql如何实现新闻发布系统的开发

发布时间:2021-03-05 15:54:31 来源:亿速云 阅读:305 作者:TREX 栏目:开发技术

本篇内容主要讲解“用PHP+mysql如何实现新闻发布系统的开发”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“用PHP+mysql如何实现新闻发布系统的开发”吧!

新闻发布系统

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">
<h2 align="center">新闻首页</h2>
<h4 align="center"><a href="action.html" rel="external nofollow" >新建新闻</a>&nbsp;&nbsp;修改新闻&nbsp; &nbsp; 删除新闻&nbsp;&nbsp;<a href="ssxw.html" rel="external nofollow" >搜索新闻</a></h4>
</body>

首页效果图

用PHP+mysql如何实现新闻发布系统的开发

新建新闻

<title>插入新闻</title>
</head>

<body>
<form action="adds.php" method="post">
<h4 align="center">插入新闻</h4>
<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如何实现新闻发布系统的开发”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI