本文实例为大家分享了php留言板功能的具体代码,供大家参考,具体内容如下
数据库用到的三张表
一.登录界面 (denglu.php login.php)
1.denglu.php
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 |
< html > < head > < meta charset = "UTF-8" > < title >< CODE> < CODE> < body > < h1 >开发部内部留言板< CODE> < form action = "login.php" method = "post" > < div >用户名:< input type = "text" name = "UserName" />< CODE> < div >口令:< input type = "password" name = "PassWord" />< CODE> < input type = "submit" value = "登录" /> < a href = "denglu.php" style = "text-decoration:none" >< input type = "button" value = "复位" />< CODE> < CODE> < CODE> < CODE> |
2.login.php
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 |
session_start(); $UserName = $_POST [ "UserName" ]; $PassWord = $_POST [ "PassWord" ]; require "DBDA.class1.php" ; $db = new DBDA(); $sql = "select PassWord from yuangong where UserName = '{$UserName}'" ; $arr = $db ->query( $sql ); if ( count ( $arr )) { if ( $arr [0][0] == $PassWord && ! empty ( $PassWord )) { //存储用户名 $_SESSION [ "UserName" ] = $UserName ; header( "location:main.php" ); } } else { header( "location:denglu.php" ); } |
二.主界面(main.php tuichu.php)
1.main.php
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 |
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> < head > < meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" /> < title >无标题文档< CODE> < CODE> < body >
php session_start(); // 防止绕过登陆直接进入主界面 if(empty($_SESSION["UserName"])) { header("location:denglu.php"); exit; } require "DBDA.class1.php"; $ db = new DBDA(); $UserName = $_SESSION["UserName"]; ?> < div > < a href = "fabu.php" >发布信息< CODE> < a href = "tuichu.php" >退出系统< CODE> < CODE> />< br /> < h1 >留言信息:< CODE> < table width = "100%" border = "1" > < tr > < td >发送人< CODE> < td >发送时间< CODE> < td >接收人< CODE> < td >信息内容< CODE> < CODE>
php //显示接收者是我的,或者是所有人的 $ sql = "select * from liuyan where Recever='{$UserName}' or Recever='suoyou'" ; $arr = $db->query($sql); foreach($arr as $v) { echo "< tr > < td >{$v[1]}< CODE> < td >{$v[3]}< CODE> < td >{$v[2]}< CODE> < td >{$v[4]}< CODE> < CODE> } ?> < CODE> < CODE> < CODE> |
2.tuichu.php
?
1
2
3
4 |
session_start(); unset( $_SESSION [ "UserName" ]); header( "location:denglu.php" ); |
三.发送页面(fabu.php fabuchuli.php)
1.fabu.php
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 |
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> < head > < meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" /> < title >无标题文档< CODE> < CODE> < body > < div > < a href = "main.php" >查看信息< CODE> < a href = "tuichu.php" >退出系统< CODE> < CODE> < h1 >信息发送:< CODE> < form action = "fabuchuli.php" method = "post" > < div >接收人: < select name = "jsr" > < option value = "suoyou" >所有人< CODE>
php session_start(); $UserName = $_SESSION["UserName"]; require"DBDA.class1.php"; $ db = new DBDA(); //方法一 $ sql = "select friend.Friend,yuangong.Name from friend,yuangong where friend.Friend = yuangong.UserName and friend.Me = '{$UserName}'" ; $arr = $db->query($sql); foreach($arr as $v) { echo "< option value = '{$v[0]}' >{$v[1]}< CODE> } //方法二 /*$sql = "select Friend from friend where Me ='{$UserName}'"; $arr = $db->query($sql); foreach($arr as $v) { $v[0]; $sname = "select Name from yuangong where UserName = '{$v[0]}'"; $aname = $db->query($sname); echo"< option value = '{$v[0]}' >{$aname[0][0]}< CODE> }*/ ?> < CODE> < div >信息内容:< textarea name = "neirong" >< CODE> < input type = "submit" value = "发送" /> < a href = "fabu.php" style = "text-decoration:none" >< input type = "button" value = "复位" />< CODE> < CODE> < CODE> < CODE> |
2.fabuchuli.php
?
1
2
3
4
5
6
7
8
9
10
11
12
13 |
session_start(); $UserName = $_SESSION [ "UserName" ]; $jsr = $_POST [ "jsr" ]; $nr = $_POST [ "neirong" ]; $Times = date ( "Y-m-d H:i:s" ); require "DBDA.class.php" ; $db = new DBDA(); $sql = "insert into liuyan values('','{$UserName}','{$jsr}','{$Times}','{$nr}')" ; $db ->query( $sql ,0); header( "location:fabu.php" ); |
以上就是本文的全部内容,希望对大家的学习有所帮助
jsp复习资料汇总
[JSP]2017年1月24日asp教程编程辅导汇总
[ASP]2016年12月2日JSP快速入门教程汇总
[JSP]2016年12月2日jsp基本用法和命令汇总
[JSP]2016年10月3日ASP编码教程:如何实现/使用缓存
[ASP]2015年4月15日