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


Posted in PHP onJuly 25, 2008

guestbook.php: 
<head> 
<meta http-equiv="Content-Language" c> 
<meta http-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> 
<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>"); 
  } 
?>

PHP 相关文章推荐
PHP+javascript液晶时钟
Oct 09 PHP
php 破解防盗链图片函数
Dec 09 PHP
mysql From_unixtime及UNIX_TIMESTAMP及DATE_FORMAT日期函数
Mar 21 PHP
php自定义函数之递归删除文件及目录
Aug 08 PHP
php在服务器执行exec命令失败的解决方法
Mar 03 PHP
php中filter函数验证、过滤用户输入的数据
Jan 13 PHP
php教程之魔术方法的使用示例(php魔术函数)
Feb 12 PHP
php实现递归抓取网页类实例
Apr 03 PHP
php自动载入类用法实例分析
Jun 24 PHP
PHP实现查询手机归属地的方法详解
Apr 28 PHP
PHP实现的各类hash算法长度及性能测试实例
Aug 27 PHP
ThinkPHP框架整合微信支付之JSAPI模式图文详解
Apr 09 PHP
简单示例AJAX结合PHP代码实现登录效果代码
Jul 25 #PHP
PHP4中session登录页面的应用
Jul 25 #PHP
PHP 表单提交给自己
Jul 24 #PHP
PHP 得到根目录的 __FILE__ 常量
Jul 23 #PHP
jq的get传参数在utf-8中乱码问题的解决php版
Jul 23 #PHP
使用PHP socke 向指定页面提交数据
Jul 23 #PHP
php sprintf()函数让你的sql操作更安全
Jul 23 #PHP
You might like
php中{}大括号是什么意思
2013/12/01 PHP
windows7下php开发环境搭建图文教程
2015/01/06 PHP
php实现用于删除整个目录的递归函数
2015/03/16 PHP
php简单实现多语言切换的方法
2016/05/09 PHP
JavaScript 拾漏补遗
2009/12/27 Javascript
浏览器缩放检测的js代码
2014/09/28 Javascript
javascript实现类似超链接的效果
2014/12/26 Javascript
通过伪协议解决父页面与iframe页面通信的问题
2015/04/05 Javascript
在JavaScript中访问字符串的子串
2015/07/07 Javascript
jQuery插件HighCharts绘制2D半圆环图效果示例【附demo源码下载】
2017/03/09 Javascript
js简单实现网页换肤功能
2017/04/07 Javascript
Angular 4.x中表单Reactive Forms详解
2017/04/25 Javascript
AngulaJS路由 ui-router 传参实例
2017/04/28 Javascript
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#‘的解决方法
2017/06/17 Javascript
vue中的ref和$refs的使用
2018/11/22 Javascript
ES6模板字符串和标签模板的应用实例分析
2019/06/25 Javascript
基于vuex实现购物车功能
2021/01/10 Vue.js
[01:37]DOTA2超级联赛专访ChuaN 传奇般的电竞之路
2013/06/19 DOTA
python和pyqt实现360的CLable控件
2014/02/21 Python
Python正则抓取网易新闻的方法示例
2017/04/21 Python
Python实现判断字符串中包含某个字符的判断函数示例
2018/01/08 Python
利用Python在一个文件的头部插入数据的实例
2018/05/02 Python
对python模块中多个类的用法详解
2019/01/10 Python
Python-openCV读RGB通道图实例
2020/01/17 Python
Tensorflow 多线程设置方式
2020/02/06 Python
什么是Python变量作用域
2020/06/03 Python
PyQt5的相对布局管理的实现
2020/08/07 Python
python实现AdaBoost算法的示例
2020/10/03 Python
pycharm激活码2020最新分享适用pycharm2020最新版亲测可用
2020/11/22 Python
马来西亚排名第一的宠物用品店:Pets Wonderland
2020/04/16 全球购物
人事行政主管岗位职责
2013/12/22 职场文书
学校采购员岗位职责
2014/01/02 职场文书
写给女生的道歉信
2014/01/14 职场文书
青年志愿者活动总结
2014/04/26 职场文书
2014年社区卫生工作总结
2014/12/18 职场文书
python 学习GCN图卷积神经网络
2022/05/11 Python