无为清净楼资源网 Design By www.qnjia.com
本文实例为大家分享了PHP留言本功能的具体代码,供大家参考,具体内容如下
index.php
<"conn.php"; $pagesize=5; //每页显示5条数据 $sql="select count(*) from guestlist "; //选择数据库,计算符合条件的行数并返回行数 $result= mysql_query($sql); //执行,如果成功则返回结果集(从数据库中找到所有的数据,返回条数) $row = mysql_fetch_row($result); //获得数组 Array[0]="数据库里的总条数" $infoCount =$row[0]; //获得总条数:取得数组中的值$row[0]="数据库里的总条数" $pageCount = ceil($infoCount/$pagesize); //获取总页数(总个数/每页的个数5) $currpage=empty ($_GET["page"])"page"]; //如果当前页为空 则定义page=1即$currpage=1反之亦然 if($currpage>$pageCount) //如果输入的页数超过总页数则默认跳转到最后一页 { $currpage=$pageCount; } "utf-8" /> <title></title> <!--此处添加了bootstrip样式--> <link href="../dist/css/bootstrap.min.css" rel="external nofollow" type="text/css" rel="stylesheet" /> <link href="css/index.css" rel="external nofollow" type="text/css" rel="stylesheet" /> <script> function test(){ var sum; if(document.frm.title.value==''){ alert('请填写标题'); return false; }else{ sum =document.frm.title.value.length; if(sum<5 || sum>20){ alert('标题长度 5-20个字符'); return false; } } if(document.frm.username.value==''){ alert('请填写用户网名'); return false; } if(document.frm.content.value==''){ alert("请填写内容"); return false; } return true; } </script> </head> <body> <div class="content"> <h5 style="color: red;"><"bt"> <li>留言标题</li> <li>用户网名</li> <li>时间</li> </ul> <"select * from guestlist order by id desc limit ".($currpage-1)*$pagesize.",".$pagesize); while($row= mysql_fetch_assoc($re)) //得到一行数据的数组,再执行则得到再下一行,如果得到是最后一行,那么再执行则返回false { "nr"> <li><"title"];"username"];"addtime"];"lynr"> <p><strong>留言内容:</strong></p><span><"content"];"width:800px"/> <ul class="pagination"> <!--上一页--> <"<li><a href=".($i-1).">«</a></li>"; } } "<li ><a style='background-color:#EEEEEE'>$i</a></li>"; }else{ echo "<li><a href='";} } "<li><a href=".($i+1).">»</a></li>"; } } "color:red">发表留言</strong> <form action="result.php" method="post" name="frm" onsubmit="return test()"> <table cellpadding="0" cellspacing="0" > <tr> <td >留言标题:</td> <td><input type="text" name="title" autocomplete="off"/></td> </tr> <tr> <td>网名:</td> <td><input type="text" name="username" autocomplete="off"/></td> </tr> <tr> <td>留言内容:</td> <td><textarea name="content" cols="42" rows="5" autocomplete="off"/></textarea></td> </tr> <tr> <td></td> <td><input class="btn" type="submit" name="submit" value="提交"/></td> </tr> </table> </form> </div> </body> </html>
conn.php
<"localhost","root"," "); mysql_select_db("guestbook"); mysql_query("set names utf-8"); if(!$link){ die("Connection failed: " . mysqli_connect_error()); } //echo "链接成功"; "htmlcode"><"conn.php"; $title = $_REQUEST['title']; $username = $_REQUEST['username']; $content = $_REQUEST['content']; $content = str_replace("\n","<br>",str_replace(" "," ",$content)); //显示'空格'和'回车' $week = '星期'.mb_substr( "日一二三四五六",date("w"),1,"utf-8" ); $isok =mysql_query("insert into guestlist(title,username,content,addtime)values('$title','$username','$content','".date("Y-m-d H:i:s")." $week ')"); if($isok) { echo "<script> alert('提交成功'); location.href='index.php'; </script>"; }else { echo "<script> alert('提交失败'); location.href='index.php'; </script>"; } "htmlcode">body{margin:0;padding:0;} ul,li{list-style: none;margin:0;padding:0;} a{text-decoration: none;} .content{ width:800px; margin:0 auto; } .bt{ width:799px; height:20px; text-align: center; background:#EB9316; margin:0 0 5px 0; } .bt>li{ float:left; width:265px; height:20px; text-align: center; line-height: 20px; font-size:13px; } .nr{ float:left; /*如果不浮动 后面的lynr会受影响*/ width:799px; height:20px; text-align: center; background:#B9DEF0; } .nr>li{ float:left; width:265px; height:20px; text-align: center; line-height: 20px; font-size:13px; } .lynr{ float:left; /*如果不浮动会 布局会乱*/ width:800px; margin:1px 0 1px 0; } .content p{ width:70px; height:50px; float:left; } .content span{ display: block; width:710px; float:left; } td{ width:80px; padding:5px 0; /*border: 1px solid #79ABFE;*/ } td input,textarea{ border: 1px solid #79ABFE; } /*tr{ display:block; /*将tr设置为块体元素 显示块状后 就将其包围住了 不是一个矩形了 }*/dist/css/bootstrap.min.css(自己下载)
效果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
标签:
PHP,留言本
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC
- 藤泽麻衣《空みあげて》[WAV]
- 纯音入心系列纯音乐《中国古筝经典名曲》1CD[MP3][1.3GB]
- 纯音入心系列纯音乐《古筝新奏:岁月静好与筝语,细水流年与筝同》1CD[MP3][846.9MB]
- 670《脆弱敏感小女生》[320K/MP3][27.53MB]
- 曾琳.2011-好好爱我【南方】【WAV+CUE】
- 范晓萱.1995-RAIN【福茂】【WAV+CUE】