看了很多网上的留言板,都和想要的效果不一样,于是自己也上传个,不知道对您有帮
助没,大家相互学习下。
本留言板极其简单,只实现
‘增’,‘删’,‘改’,‘查’功能,用了四个文件,其中 db.php
是在其余三个文件中都用到的,
liuyan3.php 是首页文件,act.php 是后台文件,所有的
操作必须通过这个文件更改,这样可以更安全,
update.php 是一个修改(编辑)文件。实
现修改跳转功能。
首先创建数据库:
demo1 数据表:table
一下是代码复制:
db.php 文件
<?php
class Db{
function __construct(){
mysql_connect('localhost','root') or die ('连接失败'.mysql_error());
mysql_select_db('demo1');
}
function select($a){
return mysql_query($a); // 这个函数完全可以不要,只是为了练习封装;
}
function del($b){
mysql_query($b); // 这个函数完全可以不要,只是为了练习封装;
}
}
?>
liuyan3.php 首页文件
<form action="/daima/act.php?act=add" method="post">
标题:
<input style="width:230" type="text" name="title" /><br />
内 容 :
<textarea style="vertical-align:top" rows="10" cols="30"
name="content"></textarea><br /><br/>
<input style="margin-left:130px;width:60px;height:30px;" type="submit"
value="提交">
</form>
<?php
include('db.php');
$db=new Db;
$sql="select * from demo1.table order by id desc";
$result= $db->select($sql) or die('查询失败' . mysql_error());