基於PHP+mysql實現新聞釋出系統的開發
阿新 • • 發佈:2020-08-07
新聞釋出系統
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> 修改新聞 刪除新聞 <a href="ssxw.html" rel="external nofollow" >搜尋新聞</a></h3> </body>
首頁效果圖
新建新聞
<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
<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
<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新聞釋出系統內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!