留言板登录界面
1 <input type="hidden" name="info_id" value="<?php echo $_GET["info_id"]; ?>" id="id"> 2 <form action="chuli/list.php" method="post"> 3 <table border="1" > 4 <tr> 5 <td colspan="2" style="text-align: center">开发部内部留言板</td> 6 </tr> 7 <tr> 8 <td style="text-align: center">用户名:</td> 9 <td><input type="text" name="id"></td> 10 </tr> 11 <tr> 12 <td style="text-align: center">口令:</td> 13 <td><input type="password" name="screct"></td> 14 </tr> 15 <tr> 16 <td colspan="2" style="text-align: center"> 17 <button>登录</button> 18 <input type="reset" value="重置"> 19 </td> 20 </tr> 21 </table> 22 </form>
登录信息处理代码
1 <?php 2 //连接数据库 3 $db = new MySQLi("localhost","root","","z_text"); 4 !mysqli_connect_error() or die("连接失败"); 5 $db -> query("set names utf8"); 6 //接受input传过来的值 7 $id = $_POST["id"]; 8 $screct=$_POST["screct"]; 9 //查询数据中 10 $sql = "select username,password from yuangong where username = ‘$id‘"; 11 $ret = $db -> query($sql); 12 $arr = $ret ->fetch_row(); 13 if($arr[1] == false){ 14 header("location:../index.php?id=‘2‘"); 15 die; 16 }else{ 17 header("location:../index.php?id=‘3‘"); 18 } 19 //数组遍历 20 var_dump($arr); 21 var_dump($id); 22 var_dump($screct); 23 if($arr[0] == $id && $arr[1]==$screct){ 24 header("location:../login.php?info_id=$id"); 25 } 26 27 28 ?>
登录首页
1 <?php 2 //连接数据库 3 $db = new MySQLi("localhost","root","","z_text"); 4 !mysqli_connect_error() or die("连接失败"); 5 $db -> query("set names utf8"); 6 7 //查询数据库中的内容 8 $sql = "select * from liuyan"; 9 $ret = $db->query($sql); 10 $arr = $ret->fetch_all(); 11 ?> 12 13 <a href="info.php?info_id=<?php echo $_GET[info_id] ?>">发布信息 14 <!--<input type="hidden" name="login_name" value="">--> 15 </a> 16 <a href="index.php">退出系统</a><br> 17 留言信息: <br> 18 <table border="1"> 19 <tr> 20 <td>发送人</td> 21 <td>发送时间</td> 22 <td>接收人</td> 23 <td>信息内容</td> 24 </tr> 25 <?php foreach ($arr as $k=>$v){ ?> 26 <tr> 27 <td><?php echo $v[1] ?></td> 28 <td><?php echo $v[3] ?></td> 29 <td><?php echo $v[2] ?></td> 30 <td><?php echo $v[4] ?></td> 31 </tr> 32 <?php }?> 33 </table>
留言界面
1 <a href="chakan.php?id=<?php echo $_GET["info_id"]?>">查看信息</a> <a href="index.php">退出系统</a> <br> 2 信息发送: <br> 3 <form action="chuli/info.php?id=<?php echo $_GET["info_id"]?>" method="post"> 4 <input type="hidden" name="chakan_id" value="<?php echo $_GET["info_id"]?>"> 5 <input type="hidden" name="id"> 6 <input type="hidden" name="time"> 7 <table border="1"> 8 <tr> 9 <td>接收人</td> 10 <td><input type="text" name="jieshou"></td> 11 </tr> 12 <tr> 13 <td>信息内容</td> 14 <td><input type="textarea" name="info"></td> 15 </tr> 16 <tr> 17 <td colspan="2"> 18 <button>发送</button> 19 <input type="reset" value="复位"> 20 </td> 21 </tr> 22 </table> 23 </form>
留言处理代码
1 <?php 2 //连接数据库 3 $db = new MySQLi("localhost","root","","z_text"); 4 !mysqli_connect_error() or die("连接失败"); 5 $db -> query("set names utf8"); 6 7 $info_id=$_POST["chakan_id"]; //接受登录传过来的值 8 9 $sql1 ="select name from yuangong where username=‘$info_id‘"; 10 $name = $db -> query($sql1); 11 $name1 = $name ->fetch_row(); 12 var_dump($name1[0]); 13 $id=$_POST["id"]; //id值 14 $jieshou = $_POST["jieshou"];//接受人 15 $info = $_POST["info"]; //信息内容 16 $time =date("Y-m-d"); //时间 17 18 $sql = "insert into liuyan(".//添加 19 "sender,". 20 "recever,". //添加接收人 21 "comment,". //添加信息内容 22 "times". //添加时间 23 ") values(‘$name1[0]‘,‘$jieshou‘,‘$info‘,‘$time‘)"; 24 // var_dump("$sql"); 25 // $sql = "insert into liuyan(‘Sender‘,‘Recever‘,‘Times‘,‘Comment‘) values(‘$name1[0]‘,‘$jieshou‘,‘$time‘,‘$info‘)"; 26 var_dump(1313); 27 var_dump($sql); 28 29 $ret =$db-> query($sql); 30 header("location:../login.php?info_id=$info_id"); 31 ?>
查看留言内容
代码
1 <?php 2 //连接数据库 3 $db = new MySQLi("localhost","root","","z_text"); 4 !mysqli_connect_error() or die("连接失败"); 5 $db -> query("set names utf8"); 6 7 $id = $_GET["id"]; //接受登录传过来的值 8 //var_dump($id); 9 $sql1 ="select name from yuangong where username=‘$id‘"; 10 //var_dump($sql1); 11 $name = $db -> query($sql1); 12 $name1 = $name ->fetch_row(); 13 //var_dump($name1); 14 15 $sql2 ="select * from liuyan where recever=‘$name1[0]‘ or recever=‘所有人‘"; 16 //var_dump($sql2); 17 $ret = $db -> query($sql2); 18 $arr = $ret ->fetch_all(); 19 20 //var_dump($arr); 21 ?> 22 <form action="chuli/del.php?info_id=<?php echo $id ?>" method="post"> 23 <table border="1"> 24 <tr> 25 <td>发送人</td> 26 <td>发送时间</td> 27 <td>接收人</td> 28 <td>信息内容</td> 29 <td>删除</td> 30 </tr> 31 <?php foreach ($arr as $v){ ?> 32 <tr> 33 <input type="hidden" name="sql" value="<?php echo $v[0]?>"> 34 <td><?php echo $v[1]?></td> 35 <td><?php echo $v[3]?></td> 36 <td><?php echo $v[2]?></td> 37 <td><?php echo $v[4]?></td> 38 <td><button>删除</button></td> 39 </tr> 40 41 <?php } ?> 42 </table> 43 <a href="info.php?info_id=<?php echo $id ?>">返回</a> 44 45 </form>
注意事项及其解决办法
1.当一个变量需要每个页面都需要用到时候
一、定义一个变量传给每个页面(名字最好相同)
二、$_SESSION["uid"] = "变量";(在每个页面都写,写的页面通用一个变量)
2.数据库传值问题
当数据库字符长度规定长度为0时不能传值
字符类型为text时,字符长度可以是0,并且传的值没有限制
3.常见问题及其解决办法
找到出错页面,输出页面中的变量,与应该出现的值比较,分析原因
4.js传值方法(get传值)
location.href = "chuli/delete.php?变量"
5.php传值方法
header("location:../login.php?键=值");
6.php获取时间方法
$time =date("Y-m-d");