<!DOCTYPE html> <?php session_start();?> <html lang="en"> <head> <meta charset="UTF-8"> <!--标签页标题--> <title>哈哈留言板</title> </head> <body> <p align="center">哈哈留言板</p><br> <p>请在此处留言<br> <!--表单,用于输入数据,并提交给liuyanban.php,进行数据的存入--> <form action="liuyanban.php" method="post"> <input name= "kuang" type="text" style="width:500px;height:80px;" /> <input type="submit" value="留言"/> </form> </p> <br> <p> <b>留言区</b> <br><br> <!--php内嵌代码,用于在lyb数据库word表中查出全部留言并输出在页面上--> <?php $con = mysqli_connect("127.0.0.1", "root", "", "lyb"); $result2 = mysqli_query($con,"SELECT * FROM liuyan"); while ($row=mysqli_fetch_array($result2)) { echo $row['word']; echo "<br><br>"; } mysqli_close($con); ?> </p> </body> </html>
<?php /** * Created by PhpStorm. * User: chm * Date: 2016/3/29 * Time: 9:55 */ session_start(); /* * 这里是登录界面后台 三层if语句,一层判断表单中ID为namel的框体数据是否被成功提出 第二层判断namel输入是否为空 第三层判断pwdl输入是否为空 然后进入数据库用户信息的比对过程,以u_name为条件,查询u_pwd */ if(isset($_POST[@namel])) { if ($_POST[@namel] != null) { if($_POST[@pwdl] != null){ $con = mysqli_connect("127.0.0.1","root","","lyb"); $name=$_POST[@namel]; $result = mysqli_query($con,"SELECT u_pwd FROM user WHERE u_name='$name'"); //加一条提取数组的哈哈哈哈哈哈哈哈哈 $hei = mysqli_fetch_assoc($result); //var_dump($result); $he="$hei[u_pwd]"; //echo $hei; if ($he == $_POST[@pwdl]) { $_SESSION["t"]=$name; header("refresh:1;url=liuyan.php");//$url就是你的跳转路径 echo "登录成功,稍后跳转至留言板"; //echo $he;//测试代码 mysqli_close($con); } else { echo "用户名或密码错误!"; header("refresh:1;url=login.html");//$url就是你的跳转路径 } } else { echo "密码呢?"; header("refresh:1;url=login.html"); } } else{ echo "还未输入用户名,whatareyou弄撒类"; header("refresh:1;url=login.html");//$url就是你的跳转路径 } } /* * 这里是留言板后台 依然是先判断是否提取数据成功,然后判断全局回话session是否为空,这个是空的说明还未登录,需要回到登录页面 如果session非空,则已经登录 判断留言框是否为空,非空则发送成功 */ if(isset($_POST[@kuang])) { if (@$_SESSION["t"] == null){ echo "请先登录"; header("refresh:1;url=login.html"); } else { if ($_POST[@kuang] != null) { $con = mysqli_connect("127.0.0.1", "root", "", "lyb"); date_default_timezone_set('PRC'); $haha = date('Y-m-d H:i:s', time()) . '<br>' . $_SESSION["t"] . ':' . $_POST[@kuang]; $result = mysqli_query($con, "INSERT INTO liuyan (word) VALUES ('$haha')"); echo "发表成功,马上回来..."; header("refresh:1;url=liuyan.php");//$url就是你的跳转路径 } else { echo "啥都没写就想发?!!!"; header("refresh:1;url=liuyan.php");//$url就是你的跳转路径 } } } //else // echo "糟糕,没发出去,重发吧"; /* * 这里是注册后台 先判断是否提取数据成功,成功则判断前两个text是否为空,都非空,则比对第二个第三个pwd是否相同 相同则注册成功,录入数据库,不同则提示不同,重新输入 */ if(isset($_POST[@name])){ if($_POST[@name]!=null){ if($_POST[@pwd1]!=null) { if ($_POST[@pwd1] == $_POST[@pwd2]) { $con = mysqli_connect("127.0.0.1", "root", "", "lyb"); $result = mysqli_query($con, "INSERT INTO user (u_name,u_pwd) VALUES ('$_POST[name]','$_POST[pwd1]')"); echo "正在跳转到登录界面,请稍后..."; header("refresh:1;url=login.html");//$url就是你的跳转路径 mysqli_close($con); } else { echo "两次输入不同,请重新输入..."; header("refresh:1;url=zhuce.html");//$url就是你的跳转路径 } } else{ echo "密码没写呢,回去重来!"; header("refresh:1;url=zhuce.html");//$url就是你的跳转路径 } } else{ echo "名字都没写还想注册?"; header("refresh:1;url=zhuce.html");//$url就是你的跳转路径 } } //else{ // echo "哎呀糟了,提交失败请再试一次"; // header("refresh:1;url=zhuce.html");//$url就是你的跳转路径 //}
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>登录</title> </head> <body> <!--提取数据的表单--> <form action="liuyanban.php" method="post"> 用户名:<input type="text" name = "namel" /> <br> 密码:<input type="password" name = "pwdl" /> <br> <a href="zhuce.html">新用户请注册</a> <input type="submit" value = "登录"> </form> <!--注册页面链接--> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>注册界面</title> </head> <body> <!--注册页面表单--> <form action="liuyanban.php" method="post"> 用户名:<input type="text" name="name" /> <br> 密码:<input type="password" name="pwd1" /> <br> 重复输入密码:<input type="password" name="pwd2" /> <br> <input type="submit" value="注册" /> </form> </body> </html>