mianshi
mianshi\config\connect.php
链接数据库文件
<?php /** * Created by PhpStorm. * User: Administrator * Date: 2017/9/16 * Time: 9:36 */ $conn=mysqli_connect('127.0.0.1','root',''); //$create_db_sql='create database mianshi';//创建数据库 //$query_sql=mysqli_query($conn,$create_db_sql);//创建数据库 //if($query_sql){ // echo '创建成功'; //} $sele_db=mysqli_select_db($conn,'mianshi'); //选择数据库 mysqli_query($conn,'set names utf-8'); //创建表 //$create_table_sql='create table mianshi_user ( // id int NOT NULL PRIMARY KEY AUTO_INCREMENT, // user_name VARCHAR(20) NOT NULL , // pwd VARCHAR (50) NOT NULL , // head VARCHAR(255) NOT NULL // // //)'; //$query=mysqli_query($conn,$create_table_sql) ; //if($query){ // echo '创建表成功'; //}mianshi\html\index.php
<?php session_start(); ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <form action="../rule/rule_liuyan.php" method="post"> <textarea name="info" style="width: 200px;height: 100px;"></textarea> <input type="submit" value="留言"> </form> <?php include '../config/connect.php'; $page=@$_GET['page']; $num=2; $sql4='select * from mianshi_liuyanfan '; $query4=mysqli_query($conn,$sql4); $numpage=mysqli_num_rows($query4); $tobal=ceil($numpage/$num); if(empty($page)||!isset($page)){ $page=1; } $sql='select * from mianshi_liuyanfan limit '.$page.','.$num; $query=mysqli_query($conn,$sql); while ($result=mysqli_fetch_array($query)) { $sql2="select * from mianshi_user where id=".$result['uid']; $query2=mysqli_query($conn,$sql2); $result2=mysqli_fetch_array($query2); echo "<img src='".$result2['head']."' style='width:50px;height:50px'>".$result2['user_name'].'说:'.$result['info'].'<br>'; } for ($i=1;$i<=$tobal;$i++){ echo "<a href='../html/index.php?page=".$i."'>".$i."</a>   "; } ?> <br/><a href="../html/lygl.php">留言管理</a> </body> </html>mianshi\html\login.php
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>登录</title> </head> <body> <form action="../rule/rule_login.php" method="post"> 用户:<input type="text" name="username"></br> 密码:<input type="text" name="pwd"></br> <input type="submit" value="登录"></br> </form> </body> </html>mianshi\html\lygl.php
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <?php include '../config/connect.php'; $sql='select * from mianshi_liuyanfan '; $query=mysqli_query($conn,$sql); while ($result=mysqli_fetch_array($query)) { $sql2="select * from mianshi_user where id=".$result['uid']; $query2=mysqli_query($conn,$sql2); $result2=mysqli_fetch_array($query2); echo "<img src='".$result2['head']."' style='width:50px;height:50px'>".$result2['user_name'].'说:'.$result['info']."   <a href='../rule/rule_dele_ly.php?id=".$result['id']."'>修改</a>|<a href='../rule/rule_dele_ly.php?id=".$result['id']."'>删除</a><br>"; } ?> <a href="index.php">返回留言板</a> </body> </html>mianshi\html\zhuce.php
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>注册</title> </head> <body> <form action="../rule/rule_zhuce.php" method="post" enctype="multipart/form-data"> 用户名:<input type="text" name="username"><br> 密码:<input type="password" name="pwd"><br> 重复密码:<input type="password" name="pwd2"><br> 头像:<input type="file" name="head"><br> <input type="submit" value="提交"> </form> </body> </html>mianshi\rule
删除留言
mianshi\rule\rule_dele_ly.php
<?php include '../config/connect.php'; /** * Created by PhpStorm. * User: Administrator * Date: 2017/9/16 * Time: 15:13 */ $sql='delete from mianshi_liuyanfan where id= '.$_GET['id']; $query=mysqli_query($conn,$sql); if($query){ echo "<script>alert('删除成功');location.href='../html/lygl.php'</script>"; }else{ echo "<script>alert('删除失败');location.href='../html/lygl.php'</script>"; }
留言验证
mianshi\rule\rule_liuyan.php<?php session_start(); include ('../config/connect.php'); if(!$_SESSION['username']){ echo "<script>alert('请先登录');location.href='../html/login.php'</script>"; }else{ $info=$_POST['info']; $sql="select id from mianshi_user where user_name='".$_SESSION['username']."'"; $query=mysqli_query($conn,$sql); $result=mysqli_fetch_array($query); $sql2="insert into mianshi_liuyanfan (uid,info)VALUES(".$result['id'].",'".$info."') "; // echo $sql2; $query2=mysqli_query($conn,$sql2); if($query2){ echo "<script>alert('留言成功');location.href='../html/index.php'</script>"; } }登录验证
mianshi\rule\rule_login.php
<?php session_start(); include ('../config/connect.php'); $username=$_POST['username']; $pwd=$_POST['pwd']; if(!empty($username)&&!empty($pwd)&&isset($username)&&isset($pwd)){ $sql="SELECT * from mianshi_user WHERE user_name='".$username."' AND pwd='".$pwd."'"; // echo $sql; $query=mysqli_query($conn,$sql); $num=mysqli_num_rows($query); if($num==0){ echo "<script>alert('用户名不存在');location.href='../html/login.php'</script>"; }else{ $_SESSION['username']=$username; echo "<script>alert('登录成功');location.href='../html/index.php'</script>"; } }else{ echo "<script>alert('请填写全部信息');location.href='../html/login.php'</script>"; }注册验证
mianshi\rule\rule_zhuce.php
<?php session_start(); include('../config/connect.php'); /** * Created by PhpStorm. * User: Administrator * Date: 2017/9/16 * Time: 10:35 */ $username=$_POST['username']; $pwd=$_POST['pwd']; $pwd2=$_POST['pwd2']; $head=$_FILES['head']; if(!empty($username)&&$pwd==$pwd2){ $array['username']=$username; $array['pwd']=$pwd; //is_uploaded_file() 函数判断指定的文件是否是通过 HTTP POST 上传的。 if(is_uploaded_file($head['tmp_name'])){ echo '图片上传名称:'.$head['name'].'<br>'; echo '图片类型:'.$head['type'].'<br>'; echo '图片大小:'.$head['size'].'<br>'; echo '上传图片的路径:'.$head['tmp_name'].'<br>'; echo '图片错误码:'.$head['error'].'<br>'; /** * 0:文件上传成功<br/> * 1:超过了文件大小,在php.ini文件中设置<br/> * 2:超过了文件的大小MAX_FILE_SIZE选项指定的值<br/> * 3:文件只有部分被上传<br/> * 4:没有文件被上传<br/> * 5:上传文件大小为0 */ switch($head['type']){ case 'image/pjpeg': $isimage=true; break; case 'image/jpeg': $isimage=true; break; case 'image/gif': $isimage=true; break; case 'image/png': $isimage=true; break; } if(!$isimage){ echo '非法上传文件'; exit(); } echo "开始移动上传文件<br/>"; $uploadpath='../uploads/'.$head['name']; // 无法上传中文名字的文件 move_uploaded_file($head['tmp_name'],$uploadpath); if($head['error']==0){ //文件上传成功 echo '<img src="'.$uploadpath.'"style="width:250px;height:250px">' ; $array['head']=$uploadpath; } } $sql="insert into mianshi_user (user_name,pwd,head) VALUES('". $array['username']."','".$array['pwd']."','".$array['head']."')"; // echo $sql; $query=mysqli_query($conn,$sql); if($query){ echo "<script>alert('注册成功');location.href='../html/login.php'</script>"; } }else{ echo "alert('请检查填写是否出错')"; }uploads
数据库文件
/*
Navicat MySQL Data Transfer
Date: 2017-09-16 17:04:45
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for mianshi_liuyanfan
-- ----------------------------
DROP TABLE IF EXISTS `mianshi_liuyanfan`;
CREATE TABLE `mianshi_liuyanfan` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(11) DEFAULT NULL,
`info` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for mianshi_user
-- ----------------------------
DROP TABLE IF EXISTS `mianshi_user`;
CREATE TABLE `mianshi_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(20) NOT NULL,
`pwd` varchar(50) NOT NULL,
`head` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;