php+mysql简单留言板

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
<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";
?>
Update.php修改跳转文件
<?php
include ('db.php');
$db=new Db;
if(!empty($_GET['id'])){
$id=$_GET['id'];
$sql="select *from demo1.table where id=$id";
$result=$db->select($sql) or die ('查询错误' .mysql_error());
$c=mysql_fetch_array($result);
?>
<form method="post" action="/daima/act.php?act=update">
标题:<input style="width:230" type="text" name="title" value="<?php echo $c['title'] ?>" /> <br />
$db=new Db;
switch($act){
case 'add':
$sql="insert into demo1.table (title,content) values ('$title','$content')";
$db->del($sql);
break;
case 'update':
$sql="update demo1.table set title= '$title' , content= '$content' where id=$id";
标题:<input style="width:230" type="text" name="title" /><br />
内容:<textarea style="vertical-align:top" rows="10" cols="30" name="content"></textarea><br /><br/>
}
function select($a){
return mysql_query($a);//这个函数完全可以不要,只是为了练习封装;
}
function del($b){
mysql_query($b);//这个函数完全可以不要,只是为了练习封装;
}
}
?>
liuyan3.php首页文件
<form action="/daima/act.php?act=add" method="post">
echo "<a href='update.php?id=".$c['id']."'>编辑
</a>"."&nbsp;&nbsp;&nbsp;"."<a href='act.php?id=".$c['id']."&act=delete'>删除</a>";
echo "<hr>";
}
mysql_free_result($result);
看了很多网上的留言板,都和想要的效果不一样,于是自己也上传个,不知道对您有帮助没,大家相互学习下。
本留言板极其简单,只实现‘增’,‘删’,‘改’,‘查’功能,用了四个文件,其中db.php是在其余三个文件中都用到的,liuyan3.php是首页文件,act.php是后台文件,所有的操作必须通过这个文件更改,这样可以更安全,update.php是一个修改(编辑)文件。实现修改跳转功能。
<input style="margin-left:130px;width:60px;height:30px;" type="submit" value="提交" />
</form>
<?php
}
mysql_free_result($result);
?>
我也是一名初学者,代码不规范的地方请大家见谅。
$db->del($sql);
break;
case 'delete':
$sql="delete from demo1.table where id=$id1";
$db->del($sql);
break;
}
echo "<script>window.location='http://localhost/daima/liuyan3.php';</script>";
$result= $db->select($sql) or die('查询失败' . mysql_error());
while($c=mysql_fetch_array($result)){
echo $c['id']."&nbsp;".$c['title']."&nbsp;"."<br />".$c['content']."<br />";
首先创建数据库:demo1数据表:table
一下是代码复制:
db.php文件
<?php
class Db{
function __construct(){
mysql_connect('localhost','root') or die ('连接失败'.mysql_error());
mysql_selecwenku.baidu.com_db('demo1');
内容:<textarea style="vertical-align:top" rows="10" cols="30" name="content" value="<?php echo $c['content'] ?>"></textarea><br /><br/>
<input type="hidden" name="id" value="<?php echo $c['id']?>" />
mysql_close();
?>
Act.php后台文件
<?php
$act=$_GET['act'];
$id=$_POST['id'];
$id1=$_GET['id'];
$title=$_POST['title'];
$content=$_POST['content'];
include ('db.php');
相关文档
最新文档