我用php+mysql写的留言本
程序员文章站
2022-05-14 12:09:54
guestbook.php:
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">
个人主页:</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="重写" 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"];
//判断偏移量参数是否传递给了脚本,如果没有就使用默认值0
if (empty($offset))
{
$offset=0;
}
//查询结果(这里是每页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("个人主页:<font color='#3366ff'>%s</font><br>",$data["url"]);
printf("来自:<font color='#3366ff'>%s</font><br>",$data["ip"]);
printf("留言时间:<font color='#3366ff'>%s</font><br>",$data["time"]);
printf("主题:<font color='#3366ff'>%s</font><br>",$data["title"]);
printf("内容:<font color='#000000'>%s</font><br>",$data["ly"]);
printf("<hr size='1' color='#6666ff'>");
}
//下一步,要写出到其它页面的链接
if($offset) //如果偏移量是0,不显示前一页的链接
{
$preoffset=$offset-5;
print "<a href="$php_self?offset=$preoffset">前一页</a> n";
}
//计算总共需要的页数
$pages=ceil($nr/5); //$pages变量现在包含所需的页数
for ($i=1; $i <= $pages; $i++)
{
$newoffset=5*$i-5;
print "<a href="$php_self?offset=$newoffset">$i</a> n";
}
//检查是否是最后一页
$next = $offset+5;
if ($next<$nr)
{
print "<a href="$php_self?offset=$next">下一页</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("留言失败!");
printf("<a href='javascript:history.back()'>返回</a>");
}
?>
可到http://xinai.oso.com.cn/class/guesttap.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">
个人主页:</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="重写" 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"];
//判断偏移量参数是否传递给了脚本,如果没有就使用默认值0
if (empty($offset))
{
$offset=0;
}
//查询结果(这里是每页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("个人主页:<font color='#3366ff'>%s</font><br>",$data["url"]);
printf("来自:<font color='#3366ff'>%s</font><br>",$data["ip"]);
printf("留言时间:<font color='#3366ff'>%s</font><br>",$data["time"]);
printf("主题:<font color='#3366ff'>%s</font><br>",$data["title"]);
printf("内容:<font color='#000000'>%s</font><br>",$data["ly"]);
printf("<hr size='1' color='#6666ff'>");
}
//下一步,要写出到其它页面的链接
if($offset) //如果偏移量是0,不显示前一页的链接
{
$preoffset=$offset-5;
print "<a href="$php_self?offset=$preoffset">前一页</a> n";
}
//计算总共需要的页数
$pages=ceil($nr/5); //$pages变量现在包含所需的页数
for ($i=1; $i <= $pages; $i++)
{
$newoffset=5*$i-5;
print "<a href="$php_self?offset=$newoffset">$i</a> n";
}
//检查是否是最后一页
$next = $offset+5;
if ($next<$nr)
{
print "<a href="$php_self?offset=$next">下一页</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("留言失败!");
printf("<a href='javascript:history.back()'>返回</a>");
}
?>
可到http://xinai.oso.com.cn/class/guesttap.php查看
【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】