hq金水

愿你是阳光,明媚不忧伤~
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

案例:简单留言板

Posted on 2016-06-30 17:01  hq金水  阅读(162)  评论(0编辑  收藏  举报

主页代码:

<style type="text/css">
*{
    margin:0px;
    padding:0px;
    }

#a{
    margin:10px auto;
    width:300px;
    height:100px;
    }
#b{
    border:#000 1px solid;
    width:300px;
    height:100px;
    margin:10px auto;
    }
#aa{
    width:300px;
    height:100px;
    }
</style>
</head>

<body>
<br />
<br />
<br />
<h1 align="center">留言板</h1>
<div id="b">
<?php
session_start();
include ("../DBDA.php");
$dx=new DBDA();
$sql="select * from liuyan where uid='{$_SESSION['uid']}'";
$attr=$dx->Query($sql);
foreach($attr as $v)
{
    echo "<div><span>留言者:{$v[1]}</span>
    <span>留言信息:{$v[2]}</span>
    <span>留言时间:{$v[3]}</span>
    </div>";
}
?>
</div>
<div id="a">
<form action="chuli.php" method="post">
请输入留言:<input type="text" id="aa" name="text"/>
<input type="submit" value="提交"/>
</form>
</div>
</body>

处理页面:

<?php
session_start();
$_SESSION["uid"]="yonh";
include ("../DBDA.php");
$text=$_POST["text"];
$uid=$_SESSION["uid"];
$time=date("y-m-d H:i:s");
$dx=new DBDA();
$sql="insert into liuyan values('','{$uid}','{$text}','{$time}')";
//除了bool型和数字型不加'',都加''
$re=$dx->Query($sql,0);
if($re)
{
    header("location:test.php");
    }
else
{
    echo "留言失败!";
    }