PHP实现简单的新闻发布系统实例(2)

<?php header("content-type:text/html;charset=utf8"); $arr=$_POST; $id=(int)$arr['id']; require_once 'init.php'; $sql="update article set title = '$arr[title]',content = '$arr[content]' where id = '$id'"; //echo $sql; $re=mysql_query($sql);//执行sql语句 //echo $re; if($re){ echo "修改成功"; echo "<a href='https://www.jb51.net/articleList.php'>返回文章列表</a>"; }else{ echo "修改失败"; echo "<a href='https://www.jb51.net/articleList.php'>返回文章列表</a>"; } mysql_close();//关闭数据库

articleDelete.php:

<?php header("content-type:text/html;charset=utf8"); require_once 'init.php'; $id=(int)$_GET['id']; $sql="delete from article where id = '$id'"; //echo $sql; $re=mysql_query($sql); if($re){ echo "删除成功"; echo "<a href='https://www.jb51.net/articleList.php'>返回文章列表</a>"; }else{ echo "删除失败"; echo "<a href='https://www.jb51.net/articleList.php'>返回文章列表</a>"; }

init.php:

<?php //连接数据库 //五步走 //往数据库添加文章 $conn=mysql_connect("localhost","root","");//链接数据库 //echo $conn; $re=mysql_select_db("article");//选择数据库 mysql_query("set names utf8");//设置交互字符集

基础知识总结:

文章发布系统

1.articlePublish.html 发布文章页面 提交到articlePublishDo.php页面,执行写入数据库

2.articleList.php 文章列表页面

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/21c8f64e08170c4fc202c8e0cc0738a6.html