問一下怎麼建立數據庫呢?登陸時已經可以完成的了,就是留言功能不能實現
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>留言板</title>
</head>
<div> <a href='denglu.php'>返回</a></div>
<?php
error_reporting(E_ALL &~ E_NOTICE);
session_start();
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
} else echo"<br>connected!<br>";
$selected = mysql_select_db("center" ) ;
//if($selected)
//echo"selected!<br>";
mysql_query("set names 'utf8'");
$insert_account = $_SESSION['account'];
$insert_pwd = $_SESSION['password'];
echo $insert_account;
//echo $_POST[comment];
if($_SESSION['check'] ==1){
if(!empty($_POST[comment]) )
{
$sql="INSERT INTO comment (account,comment,time)VALUES('$insert_account','$_POST[comment]','$printtime')";
mysql_query($sql) or die(mysql_error());
$_SESSION['check'] = 0;
}else echo '<div align="center"><font color = "red" font size = 50>歡迎來到留言板</font>' ;
}
$insert_account
?>
<div align="center">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div valign="center">請留言 </div>
<textarea name="comment" rows="5" cols="40" ><?php
//echo readfile("webdictionary.txt");
?></textarea>
<tr><input type="submit" name="submit" value="提交" /></tr>
<p>您已提交的留言:</p>
<hr>
<?php
$pagesize=10;
mysql_select_db("center") or die("no");
//取得記錄總數$rs,計算總頁數用
$rs=mysql_query("select count(*) from comment");
$myrow = mysql_fetch_array($rs);
$numrows=$myrow[0];
echo "總留言數量:".$numrows;
//計算總頁數
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
$pages++;
//設置頁數
if (isset($_GET['page'])){
$page=intval($_GET['page']);
}
else{
//設置為第一頁
$page=1;
}
//計算記錄偏移量
$offset=$pagesize*($page - 1);
//讀取指定記錄數
$rs=mysql_query("select * from comment order by ID desc limit $offset,10");//$offset,
if ($myrow = mysql_fetch_array($rs))
{
$i=0;
?>
<table border="0" width="100%">
<tr>
<td width="50%" bgcolor="#E0E0E0">
<p align="center">留言</td>
<td width="20%" bgcolor="#E0E0E0">
<p align="center">發布時間</td>
<td width="20%" bgcolor="#E0E0E0">
<p >留言用戶</td>
</tr>
<?php
do {
$i++;
?>
<tr>
<td width="50%"><?php echo $myrow["comment"] ?></td>
<td width="20%"><?php echo $myrow["time"] ?></td>
<td width="20%"><?php echo $myrow["account"] ?></td>
</tr>
<?php
}
while ($myrow = mysql_fetch_array($rs));
echo "</table>";
}
echo "<div align='center'>共有".$pages."頁(".$page."/".$pages.")";
for ($i=1;$i< $page;$i++)
echo "<a href='comment.php?page=".$i."'>[".$i ."]</a> ";
echo "[".$page."]";
for ($i=$page+1;$i<=$pages;$i++)
echo "<a href='comment.php?page=".$i."'>[".$i ."]</a> ";
echo "</div>";
?>
<br><br><br>
</body>
<!-- <script src="/javascript/myScript.js" charset="utf-8"> </script> -->
</html>
http://blog.csdn.net/miaoling1201/article/details/3200144