PHP后台用户管理

php后台用户管理

如果有不理解的小伙伴可以私信我

1.用户登录界面

在这里插入图片描述
2.登录完成后的数据库管理界面

在这里插入图片描述
3.增加数据库值得HTML

在这里插入图片描述

首先我们需要对数据库进行配置
下面是我的两个数据库连接配置
1.<?php  
define("HOST1","localhost");
define("USER1","root");  
define("PASS1","12345678");
define("DBNAME1","test");
?>

2.<?php  
define("HOST","localhost");
define("USER","root");  
define("PASS","12345678");
define("DBNAME","test001");
?>

在这里插入PHP的register用户管理界面的代码片
```<!DOCTYPE html>
<html>
<body background="https://www.tjut.edu.cn/img-red/a.jpg">
<head>
	<meta charset="UTF-8" >
	<title>登录界面</title>
</head>
 <style type="text/css"> 
 /* body{background-color: white;} */
 h4{text-align: center ;font-family:楷体; font-size: 50px;}
 .usernameAndpws{text-align: center; font-family:宋体; font-size: 30px; border-radius: 20rpx; font-weight: 1000;}
 input{ text-align :center; border-radius: 20px;height: 30px; width: 300px; border-color: black;}
.modal-footer{text-align: center ;font-family:楷体; font-size: 30px;color: black;}
button{
    text-align: center;
    border-radius: 35px;
    border-color: black;
    height: 30px;
    width: 150px; 
    color: white;
    background-color: tomato;
}
/* input{
	border:1px solid #d2d2d2;
	background-color:transparent;
    border-radius: 20rpx;
} */
</style>

<div class="wordCans">
<div align="center"><img src="https://www.tjut.edu.cn/img-red/b-m2.png" alt="天津理工大学">

</div>
<h4>登录界面</h4>
</div>

<div class="usernameAndpws">
<form action="/phptest.php" method="post">
<div >
账号:<input type="text" name="username"  ><br>

<br>
<br>
密码:<input type="password" name="pwd" ><br>
<br>
<br> 
<button type="submit" >提交</button>
</div>
</form>
</div>
<!-- <div class="form-horizontal">密码:
    <form action="longin.php" method="POST">
    <input type="password" name="pwd"> 
</div> -->


</body>
</html>


这里是登录完成后进入管理界面
也是可以对数据库进行查询的界面`在这里插入代码片`

<!DOCTYPE html>

<html>

<?php
// 这是用户管理的验证设置权限的PHP


// $username = '1234'; 
// $password = '1234';
error_reporting(0);
$username = $_POST["username"]; 
$password = $_POST["pwd"];
$true=0;
$true1=0;
$username1=0;
$password1=0;

	require "connect.php";
	$link1=mysqli_connect(HOST1,USER1,PASS1,DBNAME1) or die(mysqli_connect_errno($link1));
	mysqli_set_charset($link1,'utf-8');

		 if(!empty($username)){
		   $sql3="SELECT* FROM register where username='$username'";
		   $result1=mysqli_query($link1,$sql3);
		   $num1=mysqli_num_rows($result1);
		   if($num1==1){
			   echo"成功";
			   $username1=$username;
			   $true1=2;
			   if(!empty($password)){
				$sql4="SELECT* FROM register where pwd='$password'";
				$result2=mysqli_query($link1,$sql4);
				$num2=mysqli_num_rows($result2);
				if($num2==1){
					echo"成功";
					$password1=$password;
					$true=2;
				}
				if($num2==0){
	header("location:register.php");
				}
			   }
			   else{
	header("location:register.php");
			   }
		   }if($num1==0){
			  
			   header("location:register.php");
		   }
		 }
	
		 if($true1==2||$true==2){
			echo"success";
		 }
		 else{

			if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || ($_SERVER['PHP_AUTH_USER'] != $username) ||
			($_SERVER['PHP_AUTH_PW'] != $password)){
			header('HTTP/1.1401 Unauthorized');
			header('WWW-Authenticate:Basic realm="Guitar Wars"');
			exit('<h2>没有权限</h2>Sorry,you must enter a username and password to access this page.');
			}
		 }


?>

<head>
	<meta charset="UTF-8" >
	<title>学生管理系统</title>
</head>

<style type="text/css">
body {background-color:indianred;}
.wrapper {width: 1500px;margin: 20px auto; color :rgb(254, 255, 255)}
h2 {text-align: center; font-family:楷体; font-size: 50px;}
.add {margin-bottom: 20px;}
.add a {text-decoration: none;color: #fff;background-color:green ;padding: 6px;border-radius: 5px;}
.del {margin-bottom: 10px;}
.del a {text-decoration: none;color: #fff;background-color:burlywood ;padding: 5px;border-radius: 5px;}
table,tr,td,th{ border: 2px solid white ; text-align:center; font-family:宋体; font-size: 20px; }
.agree a{color: black;}
tr {height: 50px;}
</style> 


<body >
	<div class="wrapper">
		<div align="center"><img src="https://www.tjut.edu.cn/img-red/b-m2.png" alt="天津理工大学"></div>
		<h2>学生管理系统</h2>
		<div align="center" style="width:90%;">

    <form method="post" action="phptest.php">
    <div>请输入姓名查询:
	<input type="text" name="name"/> 
	<input type="submit" value="查询" name="chaxun"/>
	</div>
    </form>

    </div>
		<div class="add">
			<a href="addnews.html">增加记录</a>
		</div>
		<table width="1500">
		<div>	
		<tr>
				<!-- <th>ID</th> -->
				<th>ID</th>
				<th>预约部门</th>
				<th>预约部门人</th>
				<th>来访时间</th>
				<th>离开时间</th>
				<th>来访人姓名</th>
				<th>来访原因</th>
				<th>事件</th>
				<th>来访方式</th>
				<th>电话号码</th>
				<th>申请时间</th>
				<th>审核</th>
				<th>审核选项</th>
				<th>删除选项</th>
			</tr>

		</div>
			<?php
			
			$tj = " 1=1 ";//恒成立条件
			$name ="";
                // 1.导入配置文件
                require "dbconfig.php";
                // 2. 连接mysql
                $link = mysqli_connect(HOST,USER,PASS,DBNAME)or die("提示:数据库连接失败!");
                 //mysqli_select_db($link,DBNAME);

                mysqli_set_charset($link,'utf-8');



				if(!empty($_POST)){
					$name = $_POST['name'];
					mysqli_query($link,'CREATE INDEX index_name
					ON user (ComePeople)');
					echo"$name";
					$tj = " ComePeople like '%{$name}%' " ;
				}
                // $sql='SELECT * from user order by openid';
				// $result=mysqli_query($link,$sql);
				// if(!empty())
				$sql1 ="select * from user where {$tj} order by openid";
				
                // 结果集
                $result = mysqli_query($link,$sql1);
                // var_dump($result);die;

				// 解析结果集
				$newsNum=mysqli_num_rows($result);  
				if (!$result) {
					printf("Error: %s\n", mysqli_error($link));
					exit();
				}
				for($i=0; $i<$newsNum; $i++){
					$row = mysqli_fetch_assoc($result);
					echo "<tr>";
					//echo"<td>{$row['id']}</td>";
					echo "<td>{$row['openid']}</td>";
					echo "<td>{$row['YuYueBuMen']}</td>";
					echo "<td>{$row['YuYueBuMenPeople']}</td>";
					echo "<td>{$row['ComeTime']}</td>";
					echo "<td>{$row['LiftTime']}</td>";
					echo "<td>{$row['ComePeople']}</td>";
					echo "<td>{$row['Work']}</td>";
					echo "<td>{$row['Thing']}</td>";
					echo "<td>{$row['Way']}</td>";
					echo "<td>{$row['Telephone']}</td>";
					echo "<td>{$row['LockDate']}</td>";
					echo "<td>{$row['alive']}</td>";
					echo "<td>
					<div class=agree>
					<a href='javascript:agree({$row['openid']})'>同意</a>
					<a href='javascript:disagree({$row['openid']})'>不同意</a>
					</div>
							
						  </td>";
						  echo"<td>
						  <div class=del>
						  <a href='javascript:del({$row['openid']})'>删除记录</a>
						  </div>
						  </td>";
					echo "</tr>";
					
				}
				
				// <a href='editnews.php?id={$row['openid']}'>修改</a>
				// 5. 释放结果集
				mysqli_free_result($result);
				if (!$result) {
					printf("Error: %s\n", mysqli_error($link));
					exit();
				}
				mysqli_close($link);
			?>

		</table>
	</div>
	
	<script type="text/javascript">
		function agree (openid) {
			if (confirm("确定同意这条访问消息吗?")){
				window.location="agree.php?openid="+openid;
			}
		}
	</script>
	<script type="text/javascript">
			function disagree (openid) {
			if (confirm("确定不通过这条访问消息吗?")){
				window.location="disagree.php?openid="+openid;
			}
		}
	</script>
		<script type="text/javascript">
			function del (openid) {
			if (confirm("确定删除这条访问消息吗?")){
				window.location="del.php?openid="+openid;
			}
		}
	</script>
	


</body>
</html>



然后是对这个界面的数据库进行增删改查
首先是增加数据的HTML

<!DOCTYPE html>  
<html>  
<head lang="en">  
    <meta charset="UTF-8">  
    <title>添加人员</title>  
</head>
<style type="text/css">
	form{
		margin: 20px;
	}
</style>
<body>
<form action="action-addnews1.php" method="post">  
    <!-- <label>Openid:</label><input type="text" name="openid"> -->
    <label>预约部门:</label><input type="text" name="YuYueBuMen">    
    <label>预约部门人:</label><input type="text" name="YuYueBuMenPeople">  
    <label>来的时间:</label><input type="date" name="ComeTime">  
    <label>离开时间:</label><input type="date" name="LiftTime">  
    <label>来访人姓名:</label><input type="text" name="ComePeople"> 
    <label>来访原因:</label><input type="text" name="Work">  
    <label>事件:</label><input type="text" name="Thing">   
    <label>来访方式:</label><input type="text" name="Way"> 
    <label>电话号码:</label><input type="text" name="Telephone"> 
    <label>申请时间:</label><input type="date" name="LockDate">  
    <input type="submit" value="提交">  
</form>  
</body>  
</html>

然后对应着该HTML进行他的PHP操作
这里有一个点就是我们要通过算法对每增加一条新数据就使得该数据
成为第一条数据(我这里用的算法是自己写的不一定是最简便的)
<!DOCTYPE html>
<html>
<body>
<?php

use function PHPSTORM_META\type;

require "dbconfig.php";
$link = mysqli_connect(HOST,USER,PASS,DBNAME) or die("提示:数据库连接失败!");
mysqli_set_charset($link,'utf-8');
$sql1='select * from user order by openid ';
$result=mysqli_query($link,$sql1);
$num=mysqli_num_rows($result);
if(!empty($num)){
    $openid=$num+1;
 }else{
     $openid=1;
 }
$YuYueBuMen=$_POST['YuYueBuMen'];
$YuYueBuMenPeople = $_POST['YuYueBuMenPeople'];
$ComeTime =$_POST['ComeTime'];
$LiftTime =$_POST['LiftTime'];
$ComePeople =$_POST['ComePeople'];
$Work =$_POST['Work']; 
$Thing =$_POST['Thing'];
$Way=$_POST['Way'];
$Telephone=$_POST['Telephone'];
$alive= "待审核";
$LockDate=$_POST['LockDate'];

$sql =  "INSERT INTO user(openid,YuYueBuMen,YuYueBuMenPeople,ComeTime,LiftTime,ComePeople,Work,Thing,Way,Telephone,LockDate,alive) 
VALUES('$openid','$YuYueBuMen','$YuYueBuMenPeople','$ComeTime','$LiftTime','$ComePeople','$Work','$Thing','$Way','$Telephone','$LockDate','$alive')";
if (mysqli_multi_query($link, $sql)) {
    echo "新记录插入成功";
    $sql2='SELECT * from user';
    // $openid2=$_GET['openid'];
    $result1=mysqli_query($link,$sql2);
    $num1=mysqli_num_rows($result1);
    $j=$num1+1;
    $m=$num1+1;
    $l=$num1-1;
    echo"$m";
    for($i=0;$i<$m;$i++){ 

        $sql3="UPDATE user set openid=$j where openid = '$num1'";
        mysqli_query($link,$sql3)or die ("错误".mysqli_error($link));
        $j--;
        $num1--;
        echo " $j";
        echo"$num1";
        if($j==1){
            echo"$j";
            $sql4="UPDATE user set openid=$j where openid='$m'";
            mysqli_query($link,$sql4)or die ("错误".mysqli_error($link));
                   break;
                    // header("Location:phptest.php"); 
        }
        //  header("Location:phptest.php"); 

    }
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($link);
}
// ,'$YuYueBuMen','$YuYueBuMenPeople','$ComeTime','$LiftTime','$ComePeople','$Work','$Thing','$Way','$Telephone','$LockDate','$alive'
//,YuYueBuMen,YuYueBuMenPeople,ComeTime,LiftTime,ComePeople,Work,Thing,Way,Telephone,LockDate,alive
?>



</body>
</html>




接下来我们就对数据进行删除该数据操作
要点就是要先识别要删除数据所在一行的主键(我这里是openid)
并且我们要完成每删除一行数据下一行数据的id会向前减1
接下来就是代码
<?php
session_start();
             require "dbconfig.php";
			 $link =mysqli_connect(HOST,USER,PASS,DBNAME)or die("提示:数据库连接失败!");
			 mysqli_set_charset($link,'UTF-8');
            //  $openid=mysqli_insert_id($openid);
			// echo"$getID";
			$getopenid = $_GET['openid'];
            // echo"$openid";
            $sql1='select * from user';
            $result=mysqli_query($link,$sql1);
            $num=mysqli_num_rows($result);
            $num1=$num-$getopenid;
            echo"$num1";
            $sql="DELETE FROM user WHERE openid='$getopenid'"or die('删除数据出错:'.mysqli_error($link)); 
            if (mysqli_multi_query($link, $sql)) {
                echo "新记录插入成功";
               for($i=0;$i<$num1;$i++){
                //    echo"$getopenid";
                   $getopenid++;
                //    echo"$getopenid";
                   $openid1=$getopenid-1;
                //    echo"$openid1";
               $sql2="UPDATE user SET openid = $openid1
                 where openid='$getopenid'";
               mysqli_query($link,$sql2)or die ('出错'.mysqli_error($link));
               
               }
                header("Location:phptest.php"); 
            } else {
                echo "Error: " . $sql . "<br>" . mysqli_error($link);
            }
            
            
			?>

然后是我们对审核的数据(待审核)进行审核
我们通过在数据里定义一个alive值默认为待审核
通过JavaScript对PHP对alive值进行改变
下面是同意和不同意的代码

1.审核通过代码
             <?php
             require "dbconfig.php";
			 $link =mysqli_connect(HOST,USER,PASS,DBNAME)or die("提示:数据库连接失败!");
			 mysqli_set_charset($link,'utf-8');
            //  $openid=mysqli_insert_id($openid);
			// echo"$getID";
			$openid = $_GET['openid'];
            echo"$openid";
            $sql="UPDATE user set alive='通过' where openid='$openid'";
            //or die('删除数据出错:'.mysqli_error($link)); 
			// $sql = 'update user set alive = "通过" from user  WHERE openid={$openid}';
            // mysqli_query($link,$sql);
            if (mysqli_multi_query($link, $sql)) {
                echo "新记录插入成功";
                header("Location:phptest.php"); 
            } else {
                echo "Error: " . $sql . "<br>" . mysqli_error($link);
            }
            
            
			?>

2.不同意代码

<?php
             require "dbconfig.php";
			 $link =mysqli_connect(HOST,USER,PASS,DBNAME)or die("提示:数据库连接失败!");
			 mysqli_set_charset($link,'utf-8');
            //  $openid=mysqli_insert_id($openid);
			// echo"$getID";
			$openid = $_GET['openid'];
            echo"$openid";
            $sql="UPDATE user set alive='不通过' where openid='$openid'";
            //or die('删除数据出错:'.mysqli_error($link)); 
			// $sql = 'update user set alive = "通过" from user  WHERE openid={$openid}';
            // mysqli_query($link,$sql);
            if (mysqli_multi_query($link, $sql)) {
                echo "新记录插入成功";
                header("Location:phptest.php"); 
            } else {
                echo "Error: " . $sql . "<br>" . mysqli_error($link);
            }
            
            
			?>

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值