PHP+MySQL实现留言板功能(三)完整版

由于前段时间过于忙碌,加上小编有重装了电脑系统,一直没有去复现这个功能,后面复现过程中,代码做了一些调整。今天我将完整版的代码和sql文件代码整理出来,供各位学习参考。

 

1.数据库SQL文件

index.php



登陆





用户登陆
用户名
密 码

doloadling.php

connect();
   $sql = "select * from tbl_ms where username='$id' and password='$password'";  
   $res = $ma1->CheckUser($link,$sql);
   if($res){
        header("Location:add.php");
   };
   if(!$res){
        echo "";
   };
?>

register.php



注册





注册用户
用户名
密 码
Again

doregister.php

connect();
$id=$_POST['id'];
$password=$_POST['password'];
$confirmPassword=$_POST['confirmPassword'];
if($password!=$confirmPassword){
	echo "";;
}
$alt="select * from tbl_ms where username='$id'";
$res = $ma1->print1($link,$alt);
if($id!=null&&$password!=null){
   $ma=new DB();
   $link=$ma->connect();
   $sql = "insert into tbl_ms (username,password) values('$id','$password')"; 
   for ($i=0; $i < count($res); $i++) {
	   if($id!=$res[$i]['username']){
	   $res = $ma->insert($link,$sql);
	   };
       if($id==$res[$i]['username']){
           echo "";
       }
   }
}
else{
    echo "";
}
?>

add.php


	  
    
	
    我的留言板.添加留言  
      
      
    

我的留言板


Add A Message What's New To Share With You。

doAdd.php

    
    connect();
    $sql = "insert into tbl_ms1 (user,title,author,ip,liuyan,time) values('$id','$title','$author','$ip','$content',now())";
    if($title!=null){
		if($author!=null){
		    $res = $ma1->insertl($link,$sql);
		};
	    if($author==null){
		    echo "";
		};
	};
	if($title==null){
	    echo "";
	};
    ?>

show.php

    
	  
      
    我的留言板.查看留言 
	
      
      
    

我的留言板


"; while($res = mysqli_fetch_array($result)){ echo "
"; echo "
"; echo "
{$res['author']} 于 {$res['time']} 给我留言

留言主题 : {$res['title']} 留言地址 : {$res['ip']}


{$res['liuyan']}


"; echo "
"; echo "
"; } echo "
"; //分页代码 //计算留言总数 $count_result = mysqli_query($con,"select count(*) as count from tbl_ms1 where user= '$id'"); $count_array = mysqli_fetch_array($count_result); //计算总的页数 $pagenum = ceil($count_array['count']/$pagesize); //echo '共',$count_array['count'],'条留言'; //echo '共',$pagenum,'页'; echo "
"; echo "
",'共',$count_array['count'],'条留言','
'; echo "
",'共',$pagenum,'页','
'; //循环输出个页数及链接 if($pagenum>1){ for($i = 1;$i<=$pagenum;$i++){ if($i == $p){ echo "
",$i,"
"; }else{ //echo '',$i,''; echo '',"
",$i,'
','
'; } } echo "
",'当前在 ',$p, ' 页',"
"; } echo "
"; echo "
"; echo "
"; echo "
"; ?>

del.php

    connect();
	$id = $_GET['id'];
	//session_start();
    //$id=$_SESSION["uid"];
    if($link){
       $sql="delete from tbl_ms1 where id =$id ";
	   //echo "$sql";
       $que=mysqli_query($link,$sql);
		if($que){
		   echo "";
		}else{
		   echo "";
		   exit;
		}
      }
    ?>

connet.php


mysqlconfig.php

 alert('注册成功!');location='index.php'; "; 
      } else { 
          echo "Error insert data: " . $link->error; 
      }

     }
    function CheckUser($link,$sql){
      $result = mysqli_query($link,$sql);
      $row = mysqli_num_rows($result);
      if($row != 0){
        return true;
        }
	  else{
        return false;
        }
     }
    function insertl($link,$sql){
       if (mysqli_query($link, $sql)) { 
          echo ""; 
       } else { 
          echo "Error insert data: " . $link->error; 
      }

     }
	 function print1($link,$sql){
        $result = mysqli_query($link,$sql);
        $data = array();
        while ($row = mysqli_fetch_array($result)) {
          $data[] = $row;
        }
        if ($data) {
          return $data;
        } else {
          return false;
        }
      }
     
}
?>

sql文件

/*
Navicat MySQL Data Transfer

Source Server         : MySQL
Source Server Version : 50617
Source Host           : localhost:3306
Source Database       : my1

Target Server Type    : MYSQL
Target Server Version : 50617
File Encoding         : 65001

Date: 2018-12-04 16:41:55
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for tbl_ms
-- ----------------------------
DROP TABLE IF EXISTS `tbl_ms`;
CREATE TABLE `tbl_ms` (
  `username` varchar(25) NOT NULL,
  `password` varchar(25) NOT NULL,
  PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for tbl_ms1
-- ----------------------------
DROP TABLE IF EXISTS `tbl_ms1`;
CREATE TABLE `tbl_ms1` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user` varchar(25) NOT NULL,
  `title` varchar(225) DEFAULT NULL,
  `author` varchar(25) DEFAULT NULL,
  `ip` varchar(25) DEFAULT NULL,
  `liuyan` varchar(225) DEFAULT NULL,
  `time` time DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `user` (`user`),
  CONSTRAINT `tbl_ms1_ibfk_1` FOREIGN KEY (`user`) REFERENCES `tbl_ms` (`username`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

css文件

index1.css

.btn {
    color: white;
    background-color: #2579d1;
    padding: 0px 1em;
    height: 35px;
	font-size:17px;
	border-radius: 12px;
   /* border: 0px solid black;*/
}

.btn:hover {
    background-color: #00ff00;
}
.index_01{
   height: 400px;width: 400px;
   margin:auto; 
   position: absolute;top: 0;
   left: 0;right: 0;bottom: 0;
   border-radius: 50%; 
   background-color: rgba(50,150,550,0.5);
   font-family:宋体;
}
div.k1 {
	margin-top:55px;
    margin-left:auto;
    margin-right:auto;
    max-width: 500px;
    background: #D2E9FF;
    padding: 20px 20px 20px 20px;
    color: #666;
}
h1 {
    font: 24px "Trebuchet MS", Arial, Helvetica, sans-serif;
    padding: 10px 10px 10px 20px;
    display: block;
    background: #C0E1FF;
    border-bottom: 1px solid #B8DDFF;
    margin: -20px -20px 15px;
    }
h1>span {
    display: block;
    font-size: 14px;
}
label {
    display: block;
    margin: 0px 0px 5px;
}
label>span {
    float: left;
    width: 22%;
    text-align: right;
    padding-right: 15px;
    margin-top: 10px;
    font-weight: bold;
}
input[type="text"],textarea,select {
    color: #888;
    width: 70%;
    padding: 0px 0px 0px 5px;
    border: 1px solid #C5E2FF;
    background: #FBFBFB;
    outline: 0;
    -webkit-box-shadow:inset 0px 1px 6px #ECF3F5;
    box-shadow: inset 0px 1px 6px #ECF3F5;
    font: 200 12px/25px "Trebuchet MS", Arial, Helvetica, sans-serif;
    height: 30px;
    line-height:15px;
    margin: 2px 6px 16px 0px;
}
textarea{
    height:100px;
    padding: 5px 0px 0px 5px;
    width: 70%;
}
.button,.reset,.submit,.button1{
    padding: 10px 30px 10px 30px;
    background: #66C1E4;
    border: none;
    color: #FFF;
    box-shadow: 1px 1px 1px #4C6E91;
    -webkit-box-shadow: 1px 1px 1px #4C6E91;
    -moz-box-shadow: 1px 1px 1px #4C6E91;
    text-shadow: 1px 1px 1px #5079A3;
}
.button:hover,.reset:hover,.submit:hover,.button1:hover{
    background: #9AFF02;
}
.wrapper {
    width: 600px;
    margin: 0 auto;
}
.ds-post-main {
    position: relative;
    width: 500px;
    margin-left: auto;
    margin-right: auto;
}
.ds-comment-body {
    z-index: 1;
    position: relative;
    left: 0;
    background: #F0F0E3;
    padding: 15px 15px 15px 30px;
    color: #696A52;
    border-radius: 5px;
    box-shadow: 0 1px 2px rgba(0,0,0,.15), 0 1px 0 rgba(255,255,255,.75) inset;
}
.ds-comment-body {
    color: #696A52;
}
.ds-avatar {
    z-index: 2;
    position: absolute;
    top: 48px;
    left: -20px;
    padding: 5px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    box-shadow: -1px 0 1px rgba(0,0,0,.15) inset;
}
.ds-avatar a {
    display: block;
    padding: 1px;
    width: 32px;
    height: 32px;
    border: 1px solid #B9BAA6;
    border-radius: 50%;
    background-color: #fff;
    -moz-transition: color 0.15s linear;
    -webkit-transition: color 0.15s linear;
    transition: color 0.15s linear;
}
a {
    text-decoration: none;
}

文件结构(.bak是备份文件,不用理会)

PHP+MySQL实现留言板功能(三)完整版_第1张图片

欢迎关注熊熊出没ING公众号,不定时跟新Java、python、信息安全等相关知识哦。

你可能感兴趣的:(留言板)