日期:2014-05-16 浏览次数:20515 次
<?php
session_start();
echo $_SESSION['username'];
if($_POST && $_POST['submit']){
$username =$_POST["username"];
$email = $_POST["email"];
$title = $_POST["title"];
$content = $_POST["content"];
$createtime = date("Y-m-d H:i:s");
$link = mysql_connect("127.0.1.1","root","")or die("不能连接服务器!可能是数据库服务器没有开启,或用户名密码错误!".mysql_error());
mysql_query("use db_leave");
mysql_select_db("db_leave",$link);
mysql_query("set names'utf8'");
$sql = "insert into l_text(id,username,email,title,content,createtime) values('','$username','$email','$title','$content','$createtime')";
$result = mysql_query($sql);
$r = mysql_query("select * from l_text");
}
?>
<html>
<body>
<div>
<ul>
<?php
while($arr = mysql_fetch_array($r)){
?>
<li>
<table>
<tr>
<td>姓名:</td>
<td><?php echo $arr["username"];?></td>
<td>邮箱:</td>
<td><?php echo $arr["email"];?></td>
<td>标题:</td>
<td><?php echo $arr["title"];?></td>
<td>留言时间:</td>
<td><?php echo $arr["createtime"];?></td>
</tr>
<tr>
<td>留言内容:</td>
<td></hr><?php echo $arr["content"];?></td>
</tr>
</table>
</li>
<?php
}
?>
</ul>
</div>
<form action="" method="post">
<tr>
<td>姓名:</td>
<td><input type="text" name="username" /></td>
<td>邮箱:</td>
<td><input type="text" name="email" /></td>
</tr>
<br>
<tr>
<td>标题:</td>
<td colspan="3"><input type="text" name="title" size="58" /></td>
</tr>
<br>
<tr>
<td>留言内容:</td>
<td colspan="3"><textarea name="content" rows="10" cols="44"></textarea></td>
</tr>
<tr>
<td colspan="4"><input type="submit" name="submit" value="提交留言" /></td>
</tr>
</form>
</body>
</html>