php mysql实现办公留言系统_PHP+mysql实现简单的留言板

这是一个使用PHP和MySQL实现的简单办公留言系统,包括连接数据库、创建数据库和表、展示留言、用户登录、注册、删除留言等功能。系统包含留言显示、用户管理以及留言验证等模块,提供了一个基础的在线交互平台。
摘要由CSDN通过智能技术生成

mianshi

mianshi\config\connect.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

session_start();?>/span>html>Documenttitle>head>textarea>form>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_liuyanfanlimit'.$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"

span><span%20style=%22color:#ffe792;%22>]."' style='width:50px;height:50px'>".$result2['user_name'].'说:'.$result['info'].'

';}

for($i=1;$i<=$tobal;$i++){

echo"".$i."&nbsp&nbsp&nbsp";}

?>留言管理a>body>html> mianshi\html\login.php

/span>html>登录title>head>用户:br>密码:br>br>form>body>html> mianshi\html\lygl.php

/span>html>Documenttitle>head>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"

span><span%20style=%22color:#ffe792;%22>]."' style='width:50px;height:50px'>".$result2['user_name'].'说:'.$result['info']."&nbsp&nbsp&nbsp]."'>修改|]."'>删除

";}

?>返回留言板a>body>html> mianshi\html\zhuce.php

/span>html>注册title>head>用户名:
密码:
重复密码:
头像:form>body>html> mianshi\rule

删除留言

mianshi\rule\rule_dele_ly.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"alert('删除成功');location.href='../html/lygl.php'";}else{

echo"alert('删除失败');location.href='../html/lygl.php'";}

留言验证 mianshi\rule\rule_liuyan.php

session_start();include('../config/connect.php');if(!$_SESSION['username']){

echo"alert('请先登录');location.href='../html/login.php'";}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"alert('留言成功');location.href='../html/index.php'";}

} 登录验证

mianshi\rule\rule_login.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"alert('用户名不存在');location.href='../html/login.php'";}else{

$_SESSION['username']=$username;echo"alert('登录成功');location.href='../html/index.php'";}

}else{

echo"alert('请填写全部信息');location.href='../html/login.php'";} 注册验证

mianshi\rule\rule_zhuce.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'].'

';echo'图片类型:'.$head['type'].'

';echo'图片大小:'.$head['size'].'

';echo'上传图片的路径:'.$head['tmp_name'].'

';echo'图片错误码:'.$head['error'].'

';/*** 0:文件上传成功* 1:超过了文件大小,在php.ini文件中设置* 2:超过了文件的大小MAX_FILE_SIZE选项指定的值* 3:文件只有部分被上传* 4:没有文件被上传* 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"开始移动上传文件";$uploadpath='../uploads/'.$head['name'];//无法上传中文名字的文件move_uploaded_file($head['tmp_name'],$uploadpath);if($head['error']==0){

//文件上传成功echo'

span><span%20style=.$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"alert('注册成功');location.href='../html/login.php'";}

}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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值