大佬教程收集整理的这篇文章主要介绍了php实现简单的留言板功能(附源码),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
1、原理
简单的说就是 数据库的创建,添加数据,显示在前端上。我的程序只是简单的留言再显示。
2、界面:
3、显示留言的界面:
4、代码
<!DOCTYPE HTML> <HTML> <Head> <Meta http-equiv="CONTENT-TYPE" ; content="text/html" ; charset="UTF-8"> <title>留言</title> <style type="text/css"> .message{ margin-top:0px; } h1{ margin-top:200px; } </style> </Head> <Body> <h1 align="center">留言板</h1> <div class="message"> <form name="addform" id="addform" method="post" action="message_handle.PHP"> <table type="text" align="center" border="1px,solid"> <input type="hidden" id="id" name="id" /> <tr> <td>标题</td> <td><input type="text" name="title" id="title"/></td> </tr> <tr> <td>作者</td> <td><input type="text" name="author" id="author"/> </td> </tr> <tr> <td>内容</td> <td><textarea name="message" id="message" cols="60" role="15"></textarea></td> </tr> <tr> <td><input type="submit" name="sumbit"/></td> <td><input type="reset" name="reset"/></td> </tr> </table> </form> </div> </Body> </HTML>
<?PHP header("CONTENT-TYPE:text/html;charset=UTF-8"); define("HOST","127.0.0.1"); define("USERNAME","root"); define("passworD",""); if($con=new MysqLi(HOST,USERNAME,passworD,"test")){ echo $con->error; } if($con->SELEct_db("messageboard")){ echo $con->error; } if($con->query("SET NAMES utf8")){ echo $con->error; } $id=$_POST["id"]; $title=$_POST["title"]; $author=$_POST["author"]; $message=$_POST["message"]; $time=date('y-m-d h:m:s'); $sql="insert into messageboard(id,title,author,message,datelinE) values('$id','$title','$author','$message','$time')"; if($str=$con->query($sql)){ echo "<script>alert('留言成功');window.LOCATIOn.href='show_message.PHP'</script>"; } else { echo "<script>alert('留言失败');window.LOCATIOn.href='messageboard.PHP'</script>"; } ?>
<?PHP header("CONTENT-TYPE:text/html;charset=UTF-8"); define("HOST","127.0.0.1"); define("USERNAME","root"); define("passworD",""); if($con=new MysqLi(HOST,USERNAME,passworD,"test")){ echo $con->error; } if($con->SELEct_db("messageboard")){ echo $con->error; } if($con->query("SET NAMES utf8")){ echo $con->error; } $sql="SELEct * from messageboard ORDER BY dateline DESC "; $str=$con->query($sql); if($str && MysqLi_num_rows($str)){ while($row= MysqLi_fetch_assoc($str)){ $data[]=$row; } } ?> <!DOCTYPE HTML> <HTML> <Head> <Meta http-equiv="CONTENT-TYPE" ; content="text/html" ; charset="UTF-8"> <title>留言板</title> <style type="text/css"> </style> </Head> <Body> <div> <?PHP if(empty($data)){ echo "当前没有留言"; } else{ foreach($data as $value) { ?> <table celLPADding="2" cellspacing="8" align="center" border="1px,solid"> <tr> <td>标题</td> <td><?PHP echo $value['title']; ?></td> </tr> <tr> <td>作者</td> <td><?PHP echo $value['author']; ?></td> </tr> <tr> <td>内容</td> <td><?PHP echo $value['message']; ?></td> </tr> <tr> <td><?PHP echo $value['dateline'];;?></td> </tr> </table> </div> <?PHP } } ?> </Body> </HTML>
5、所遇到的问题
刚开始显示页面上不能显示数据,找了半天原因,结果是因为在sql中写错了@L_674_49@方式写成了:
SELEct * from message where dateline desc;
用where得有条件,才能@L_674_49@到。得有例如:
SELEct * from message where dateline=$date;
因为我的程序没有从前个页面传递数据到这,所以只能用下面这种通过时间来排序罗列出所有数据。
SELEct * from message order by dateline;
感谢大家的阅读,以上代码有不足的地方请大家指出,希望大家可以有所收获。
本文转载自:https://blog.csdn.net/jeak2015/article/details/53440522
推荐教程:《PHP教程》
以上是大佬教程为你收集整理的php实现简单的留言板功能(附源码)全部内容,希望文章能够帮你解决php实现简单的留言板功能(附源码)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。