php+mysql写的简单留言本实例代码

时间:2021-05-26

guestbook.php:
<head>
<metahttp-equiv="Content-Language"c>
<metahttp-equiv="Content-Type"c>
<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>
<divalign="center">
<center>
<tableborder="0"cellpadding="0"cellspacing="0"width="574"height="312">
</center>
<tr>
<td><palign="center">高三<6>班留言本本</br></td>
</tr>
<tr>
<tdwidth="574"height="272"valign="top">
<formmethod="POST"action="ly.php">

<tableborder="0"cellpadding="0"cellspacing="0"width="100%">
<center>
<tr>
<tdwidth="26%"align="right">
姓名:</td>
<tdwidth="74%"><inputstyle="font-size:9pt;width:186;background-color:#f8f8f8;height:19;border:1pxsolid#9a9999"
type="text"name="T1"size="13"></td>
</tr>
<tr>
<tdwidth="26%"align="right">
EMAIL:</td>
<tdwidth="74%"><inputstyle="font-size:9pt;width:186;background-color:#f8f8f8;height:19;border:1pxsolid#9a9999"name="T2"size="13"></td>
</tr>
<tr>
<tdwidth="26%"align="right">
个人主页:</td>
<tdwidth="74%"><inputstyle="font-size:9pt;width:186;background-color:#f8f8f8;height:19;border:1pxsolid#9a9999"name="T3"size="13"value="http://";></td>
</tr>
<tr>
<tdwidth="26%"align="right">
主题:</td>
<tdwidth="74%"><inputstyle="font-size:9pt;width:186;background-color:#f8f8f8;height:19;border:1pxsolid#9a9999"name="T4"size="13"></td>
</tr>
<tr>
<tdwidth="26%"align="right"valign="top">
留言:</td>
<tdwidth="74%"><textareastyle="font-size:9pt;width:313;background-color:#f8f8f8;height:177;border:1pxsolid#9a9999"rows="10"name="S1"cols="45"></textarea></td>
</tr>
<tr>
<tdwidth="100%"align="right"colspan="2">
</td>
</tr>
</table>
<palign="center">
<inputtype="submit"value="提交"name="B1"><inputtype="reset"value="重写"name="B2"></p>
</form>
</center>
</td>
</tr>
</table>
<hrsize='1'color='#6666FF'>
</div>
<divalign="center">
<center>
<tableborder="0"cellpadding="0"cellspacing="0"width="603"height="294">
<tr>
<tdwidth="603"height="294">
<?
include("connect.rec");

$qh=mysql_query("SELECTCOUNT(*)ASrcntFROMguestbook");

$data=mysql_fetch_array($qh);

$nr=$data["rcnt"];

//判断偏移量参数是否传递给了脚本,如果没有就使用默认值0

if(empty($offset))

{

$offset=0;

}
//查询结果(这里是每页20条,但你自己完全可以改变它)

//$result=mysql_query("SELECT*fromguestbookORDERBYtimedescLIMIT$offset,5");
$result=mysql_query("SELECT*fromguestbookLIMIT$offset,5");

//显示返回的5条记录

while($data=mysql_fetch_array($result))
{
printf("姓名:<fontcolor='#000000'>%s</font><br>",$data["name"]);
printf("EMAIL:<fontcolor='#3366FF'>%s</font><br>",$data["mail"]);
printf("个人主页:<fontcolor='#3366FF'>%s</font><br>",$data["url"]);
printf("来自:<fontcolor='#3366FF'>%s</font><br>",$data["ip"]);
printf("留言时间:<fontcolor='#3366FF'>%s</font><br>",$data["time"]);
printf("主题:<fontcolor='#3366FF'>%s</font><br>",$data["title"]);
printf("内容:<fontcolor='#000000'>%s</font><br>",$data["ly"]);
printf("<hrsize='1'color='#6666FF'>");
}

//下一步,要写出到其它页面的链接

if($offset)//如果偏移量是0,不显示前一页的链接
{
$preoffset=$offset-5;
print"<ahref="$PHP_SELF?offset=$preoffset">前一页</a>n";
}

//计算总共需要的页数

$pages=ceil($nr/5);//$pages变量现在包含所需的页数

for($i=1;$i<=$pages;$i++)

{

$newoffset=5*$i-5;

print"<ahref="$PHP_SELF?offset=$newoffset">$i</a>n";

}

//检查是否是最后一页
$next=$offset+5;
if($next<$nr)
{
print"<ahref="$PHP_SELF?offset=$next">下一页</a>n";
}
printf("<ahref='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-jH:i:s");
$ip=getenv("REMOTE_ADDR");
$ly=$S1;

$result=mysql_query("insertintoguestbook(name,mail,url,ip,time,title,ly)values('$name','$mail','$url','$ip','$time','$title','$ly')");
if($result==1)
{
echo("留言成功!");
printf("<scriptlanguage='javascript'>");
printf("location='guestbook.php'");
printf("</script>");
}
else
{
echo("留言失败!");
printf("<ahref='javascript:history.back()'>返回</a>");
}
?>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章