PHP实例之新闻发布系统源码下载
PHP实例之新闻发布系统Create TABLE `news` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `p_time` DATETIME NOT NULL , `title` VARCHAR( 80 ) NOT NULL , `detail` TEXT NOT NULL ) TYPE = innodb; create table news(id int not null auto_increment primary key, p_time datetime not null, title varchar(80)not null, detail text not null )type=innodb;数据库连接:conn.php <? $conn = @mysql_connect('localhost','root','')or die(mysql_error()."不能连接到数据库!"); //连接数据库; $db = mysql_select_db('news',$conn); $page_size = 8; //每页最多显示新闻条数; ?>添加新闻页面:new.php <? $title="新闻发布系统"; include("inc/header.inc");//头文件?> <style type="text/css"> <!-- .STYLE1 {font-size: 12px} .title { font-size: 12px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; font-family: "宋体"; color: #993300; line-height: normal; height: 16px; } .field { font-family: "宋体"; font-size: 12px; color: #993333; } .STYLE2 { font-size: 16px; font-weight: bold; } --> </style> PHP+Mysql新闻发布 <form action="post.php" method="post" name="frm" id="frm"> 标题: <input name="title" type="text" class="title" id="title" size="60" maxlength="80"></td> 内容: <textarea name="textfield" cols="58" rows="6" class="field"></textarea> <input name="submit" type="submit" value="发布"></td> </form> <? include("inc/navbar.inc");//底部?>新闻处理页面:post.php <? include"conn.php"; $title=htmlspecialchars($_POST['title']); $textfield=htmlspecialchars($_POST['textfield']); $pub_time=date('Y')."-".date('m')."-".date('d')." ".date('H').":".date('i').":".date('s'); $query="insert into news(title,detail,p_time)values ('$title','$textfield','$pub_time')"; $result=mysql_query($query); if($result) { echo "发布成功!"; echo "新闻列表 继续发布"; } else { echo mysql_error().""; echo "发布失败!请返回"; } ?>新闻列表:list.php <? include "conn.php"; $query = "Select COUNT(*) FROM news"; $result = mysql_query($query); $num = mysql_num_rows($result); $page_count = ceil($num/$page_size); //$offset = ($page_count-1)*$page_size; if(empty($_GET['page'])) { $page = 1; }else { $page = $_GET['page']; if($page= $page_count; $page = $page_count-1; } } $query ="Select * FROM `news` orDER BY `id` DESC LIMIT ".($page-1)*$page_count.","."$page_size"; $result = mysql_query($query); ?> 标题 时间 <?php while($l_result = mysql_fetch_array($result)) { ?> <?php echo $l_result['id'];?> <?php echo $l_result['title'];?> <?php echo $l_result['p_time'];?> <?php } ?> 发布信息 <?php //页码显示for ($i=1;$i 标题: <?php echo $v_result['title'];?> 内容: <?php echo $v_result['detail'];?> 返回
4.71KB
文件大小:
评论区