我用php+mysql寫(xiě)的留言本
更新時(shí)間:2006年10月09日 00:00:00 作者:
guestbook.php:
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<STYLE>A:link {
COLOR: #002878; TEXT-DECORATION: none
}
A:visited {
COLOR: #002878; TEXT-DECORATION: none
}
A:active {
TEXT-DECORATION: none
}
A:hover {
COLOR: #cc1111; TEXT-DECORATION: none
}
P {
COLOR: #002878; FONT-SIZE: 9pt
}
TABLE {
COLOR: #002878; FONT-SIZE: 9pt
}
LI {
COLOR: #002878; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt
}
UL {
COLOR: #002878; FONT-SIZE: 9pt
}
}
</STYLE>
</head>
<body>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="574" height="312">
</center>
<tr>
<td><p align="center">高三<6>班留言本本</br></td>
</tr>
<tr>
<td width="574" height="272" valign="top">
<form method="POST" action="ly.php">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<center>
<tr>
<td width="26%" align="right">
姓名:</td>
<td width="74%"><input style="font-size: 9pt; width: 186; background-color: #f8f8f8; height: 19; border: 1px solid #9a9999"
type="text" name="T1" size="13"></td>
</tr>
<tr>
<td width="26%" align="right">
EMAIL:</td>
<td width="74%"><input style="font-size: 9pt; width: 186; background-color: #f8f8f8; height: 19; border: 1px solid #9a9999" name="T2" size="13"></td>
</tr>
<tr>
<td width="26%" align="right">
個(gè)人主頁(yè):</td>
<td width="74%"><input style="font-size: 9pt; width: 186; background-color: #f8f8f8; height: 19; border: 1px solid #9a9999" name="T3" size="13" value="http://"></td>
</tr>
<tr>
<td width="26%" align="right">
主題:</td>
<td width="74%"><input style="font-size: 9pt; width: 186; background-color: #f8f8f8; height: 19; border: 1px solid #9a9999" name="T4" size="13"></td>
</tr>
<tr>
<td width="26%" align="right" valign="top">
留言:</td>
<td width="74%"><textarea style="font-size: 9pt; width: 313; background-color: #f8f8f8; height: 177; border: 1px solid #9a9999" rows="10" name="S1" cols="45" ></textarea></td>
</tr>
<tr>
<td width="100%" align="right" colspan="2">
</td>
</tr>
</table>
<p align="center">
<input type="submit" value="提交" name="B1"> <input type="reset" value="重寫(xiě)" name="B2"></p>
</form>
</center>
</td>
</tr>
</table>
<hr size='1' color='#6666FF'>
</div>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="603" height="294">
<tr>
<td width="603" height="294">
<?
include ("connect.rec");
$qh=mysql_query("SELECT COUNT(*) AS rcnt FROM guestbook");
$data=mysql_fetch_array($qh);
$nr=$data["rcnt"];
//判斷偏移量參數(shù)是否傳遞給了腳本,如果沒(méi)有就使用默認(rèn)值0
if (empty($offset))
{
$offset=0;
}
//查詢(xún)結(jié)果(這里是每頁(yè)20條,但你自己完全可以改變它)
//$result=mysql_query("SELECT * from guestbook ORDER BY time desc LIMIT $offset, 5");
$result=mysql_query("SELECT * from guestbook LIMIT $offset, 5");
//顯示返回的5條記錄
while ($data=mysql_fetch_array($result))
{
printf("姓名:<font color='#000000'>%s</font><br>",$data["name"]);
printf("EMAIL:<font color='#3366FF'>%s</font><br>",$data["mail"]);
printf("個(gè)人主頁(yè):<font color='#3366FF'>%s</font><br>",$data["url"]);
printf("來(lái)自:<font color='#3366FF'>%s</font><br>",$data["ip"]);
printf("留言時(shí)間:<font color='#3366FF'>%s</font><br>",$data["time"]);
printf("主題:<font color='#3366FF'>%s</font><br>",$data["title"]);
printf("內(nèi)容:<font color='#000000'>%s</font><br>",$data["ly"]);
printf("<hr size='1' color='#6666FF'>");
}
//下一步,要寫(xiě)出到其它頁(yè)面的鏈接
if($offset) //如果偏移量是0,不顯示前一頁(yè)的鏈接
{
$preoffset=$offset-5;
print "<a href="$PHP_SELF?offset=$preoffset">前一頁(yè)</a> n";
}
//計(jì)算總共需要的頁(yè)數(shù)
$pages=ceil($nr/5); //$pages變量現(xiàn)在包含所需的頁(yè)數(shù)
for ($i=1; $i <= $pages; $i++)
{
$newoffset=5*$i-5;
print "<a href="$PHP_SELF?offset=$newoffset">$i</a> n";
}
//檢查是否是最后一頁(yè)
$next = $offset+5;
if ($next<$nr)
{
print "<a href="$PHP_SELF?offset=$next">下一頁(yè)</a> n";
}
printf("<a href='javascript:history.back()'>返回</a>")
?>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>
ly.php:
<?
include ("connect.rec");
$name = $T1;
$mail = $T2;
$url = $T3;
$title = $T4;
$time = date( "Y-m-j H:i:s" );
$ip = getenv("REMOTE_ADDR");
$ly = $S1;
$result = mysql_query("insert into guestbook (name,mail,url,ip,time,title,ly) values ('$name','$mail','$url','$ip','$time','$title','$ly')");
if ($result == 1)
{
echo("留言成功!");
printf("<script language='javascript'>");
printf("location='guestbook.php'");
printf("</script>");
}
else
{
echo("留言失?。?quot;);
printf("<a href='javascript:history.back()'>返回</a>");
}
?>
可到http://xinai.oso.com.cn/class/guesttap.php查看
【本文版權(quán)歸作者與奧索網(wǎng)共同擁有,如需轉(zhuǎn)載,請(qǐng)注明作者及出處】
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<STYLE>A:link {
COLOR: #002878; TEXT-DECORATION: none
}
A:visited {
COLOR: #002878; TEXT-DECORATION: none
}
A:active {
TEXT-DECORATION: none
}
A:hover {
COLOR: #cc1111; TEXT-DECORATION: none
}
P {
COLOR: #002878; FONT-SIZE: 9pt
}
TABLE {
COLOR: #002878; FONT-SIZE: 9pt
}
LI {
COLOR: #002878; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt
}
UL {
COLOR: #002878; FONT-SIZE: 9pt
}
}
</STYLE>
</head>
<body>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="574" height="312">
</center>
<tr>
<td><p align="center">高三<6>班留言本本</br></td>
</tr>
<tr>
<td width="574" height="272" valign="top">
<form method="POST" action="ly.php">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<center>
<tr>
<td width="26%" align="right">
姓名:</td>
<td width="74%"><input style="font-size: 9pt; width: 186; background-color: #f8f8f8; height: 19; border: 1px solid #9a9999"
type="text" name="T1" size="13"></td>
</tr>
<tr>
<td width="26%" align="right">
EMAIL:</td>
<td width="74%"><input style="font-size: 9pt; width: 186; background-color: #f8f8f8; height: 19; border: 1px solid #9a9999" name="T2" size="13"></td>
</tr>
<tr>
<td width="26%" align="right">
個(gè)人主頁(yè):</td>
<td width="74%"><input style="font-size: 9pt; width: 186; background-color: #f8f8f8; height: 19; border: 1px solid #9a9999" name="T3" size="13" value="http://"></td>
</tr>
<tr>
<td width="26%" align="right">
主題:</td>
<td width="74%"><input style="font-size: 9pt; width: 186; background-color: #f8f8f8; height: 19; border: 1px solid #9a9999" name="T4" size="13"></td>
</tr>
<tr>
<td width="26%" align="right" valign="top">
留言:</td>
<td width="74%"><textarea style="font-size: 9pt; width: 313; background-color: #f8f8f8; height: 177; border: 1px solid #9a9999" rows="10" name="S1" cols="45" ></textarea></td>
</tr>
<tr>
<td width="100%" align="right" colspan="2">
</td>
</tr>
</table>
<p align="center">
<input type="submit" value="提交" name="B1"> <input type="reset" value="重寫(xiě)" name="B2"></p>
</form>
</center>
</td>
</tr>
</table>
<hr size='1' color='#6666FF'>
</div>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="603" height="294">
<tr>
<td width="603" height="294">
<?
include ("connect.rec");
$qh=mysql_query("SELECT COUNT(*) AS rcnt FROM guestbook");
$data=mysql_fetch_array($qh);
$nr=$data["rcnt"];
//判斷偏移量參數(shù)是否傳遞給了腳本,如果沒(méi)有就使用默認(rèn)值0
if (empty($offset))
{
$offset=0;
}
//查詢(xún)結(jié)果(這里是每頁(yè)20條,但你自己完全可以改變它)
//$result=mysql_query("SELECT * from guestbook ORDER BY time desc LIMIT $offset, 5");
$result=mysql_query("SELECT * from guestbook LIMIT $offset, 5");
//顯示返回的5條記錄
while ($data=mysql_fetch_array($result))
{
printf("姓名:<font color='#000000'>%s</font><br>",$data["name"]);
printf("EMAIL:<font color='#3366FF'>%s</font><br>",$data["mail"]);
printf("個(gè)人主頁(yè):<font color='#3366FF'>%s</font><br>",$data["url"]);
printf("來(lái)自:<font color='#3366FF'>%s</font><br>",$data["ip"]);
printf("留言時(shí)間:<font color='#3366FF'>%s</font><br>",$data["time"]);
printf("主題:<font color='#3366FF'>%s</font><br>",$data["title"]);
printf("內(nèi)容:<font color='#000000'>%s</font><br>",$data["ly"]);
printf("<hr size='1' color='#6666FF'>");
}
//下一步,要寫(xiě)出到其它頁(yè)面的鏈接
if($offset) //如果偏移量是0,不顯示前一頁(yè)的鏈接
{
$preoffset=$offset-5;
print "<a href="$PHP_SELF?offset=$preoffset">前一頁(yè)</a> n";
}
//計(jì)算總共需要的頁(yè)數(shù)
$pages=ceil($nr/5); //$pages變量現(xiàn)在包含所需的頁(yè)數(shù)
for ($i=1; $i <= $pages; $i++)
{
$newoffset=5*$i-5;
print "<a href="$PHP_SELF?offset=$newoffset">$i</a> n";
}
//檢查是否是最后一頁(yè)
$next = $offset+5;
if ($next<$nr)
{
print "<a href="$PHP_SELF?offset=$next">下一頁(yè)</a> n";
}
printf("<a href='javascript:history.back()'>返回</a>")
?>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>
ly.php:
<?
include ("connect.rec");
$name = $T1;
$mail = $T2;
$url = $T3;
$title = $T4;
$time = date( "Y-m-j H:i:s" );
$ip = getenv("REMOTE_ADDR");
$ly = $S1;
$result = mysql_query("insert into guestbook (name,mail,url,ip,time,title,ly) values ('$name','$mail','$url','$ip','$time','$title','$ly')");
if ($result == 1)
{
echo("留言成功!");
printf("<script language='javascript'>");
printf("location='guestbook.php'");
printf("</script>");
}
else
{
echo("留言失?。?quot;);
printf("<a href='javascript:history.back()'>返回</a>");
}
?>
可到http://xinai.oso.com.cn/class/guesttap.php查看
【本文版權(quán)歸作者與奧索網(wǎng)共同擁有,如需轉(zhuǎn)載,請(qǐng)注明作者及出處】
相關(guān)文章
實(shí)時(shí)抓取YAHOO股票報(bào)價(jià)的代碼
實(shí)時(shí)抓取YAHOO股票報(bào)價(jià)的代碼...2006-10-10PHP數(shù)據(jù)庫(kù)操作面向?qū)ο蟮膬?yōu)點(diǎn)
PHP數(shù)據(jù)庫(kù)操作面向?qū)ο蟮膬?yōu)點(diǎn)...2006-10-10在線(xiàn)競(jìng)拍系統(tǒng)的PHP實(shí)現(xiàn)框架(一)
在線(xiàn)競(jìng)拍系統(tǒng)的PHP實(shí)現(xiàn)框架(一)...2006-10-10在線(xiàn)增減.htpasswd內(nèi)的用戶(hù)
在線(xiàn)增減.htpasswd內(nèi)的用戶(hù)...2006-10-10簡(jiǎn)單的用PHP編寫(xiě)的導(dǎo)航條程序
簡(jiǎn)單的用PHP編寫(xiě)的導(dǎo)航條程序...2006-10-10