后台用户管理

userlist.php 用户管理

<?php
    include('check.php');
	$sql="select * from user";
	$isok=mysqli_query($conn,$sql);
	while($row = mysqli_fetch_array($isok, MYSQLI_ASSOC)){
        $allrow[]=$row;
	}
include('top.php');
?>
    <h1 class="tc">用户管理</h1>
<table class="ngwtable">
    <thead>
        <tr>
            <td>用户名</td>
            <td>邮箱</td>
            <td>注册时间</td>
            <td>操作</td>
        </tr>
    </thead>
    <tbody>
        <?php foreach($allrow as $key=>$value){?>
        <tr>
            <td><?php echo $value['username'];?></td>
            <td><?php echo $value['email'];?></td>
            <td><?php echo date('Y-m-d H:i:s',$value['addtime']);?></td>
            <td><a href="useredit.php?id=<?php echo $value['id'];?>">编辑</a>
                <a href="userdel.php?id=<?php echo $value['id'];?>">删除</a>
            </td>
        </tr>
        <?php }?>
    </tbody>
</table>
</body>
</html>


useredit.php 用户资料修改

<?php
include('check.php');
if($_POST['ispost']==1){
    if (is_uploaded_file($_FILES['img']['tmp_name'])){
        $imgurl='/upload/'.$_FILES['img']['name'];
        move_uploaded_file($_FILES['img']['tmp_name'],$imgurl);
    }
    $username=$_POST['username'];
    $email=$_POST['email'];
	$sql="update user set username='".$username."',email='".$email."',img='".$imgurl."' where id='".$_GET['id']."'";
	$isok=mysqli_query($conn,$sql);
	if($isok){
		echo "修改成功";
        //header("refresh:2;url=list.php");
	}else{
		echo "修改失败";
	}
}else{
    $sql="select * from user where id='".$_GET['id']."'";
    $isok=mysqli_query($conn,$sql);
    $row = mysqli_fetch_array($isok, MYSQLI_ASSOC);
include('top.php');
?>
<div class="ngwform" style="width:800px; margin:0 auto;">
    <form action="" method="post" enctype="multipart/form-data">
        <h1 class="tc">资料修改</h1>
        <div>
            <label>账号</label>
            <input class="input" type="text" name="username" value="<?php echo $row['username']; ?>">
        </div>
        <div>
            <label>邮箱</label>
            <input class="input" type="text" name="email" value="<?php echo $row['email']; ?>">
        </div>
        <div>
            <label>头像</label>
            <input class="input" type="file" name="img" value="">
            <?php if($row['img']) echo '<img src="'.$row['img'].'">'; ?>
        </div>
        <input type="hidden" name="ispost" value="1">
        <input type="submit" class="btn" value="提交">
    </form>
</div>
</body>
</html>
<?php
}
?>


top.php头部文件

<html>
<head>
    <title></title>
    <link rel="stylesheet" href="/style/css/niuguwen.css">
</head>
<body>
<style>
	.topnav{float:left;width:100%;}
	.topnav li{float:left;margin-right:10px;}
	.topnav a{padding:20px;background:#f00;color:#FFF;line-height:35px;height:35px;font-size:18px;display:inline-block;}
</style>
<div class="topnav">
	<ul>
		<li><a href="userlist.php">用户管理</a></li>
		<li><a href="useradd.php">新增用户</a></li>
		<li><a href="loginout.php">退出</a></li>
	</ul>
</div>


useradd.php 新增用户

<?php
if($_POST['ispost']){
	include('check.php');
	if($_POST['username']&&$_POST['email']&&$_POST['psd']){
		$username=$_POST['username'];
		$psd=$_POST['psd'];
		$addtime=time();
		$email=$_POST['email'];
		$sql="INSERT INTO user(username,psd,addtime,email,img)VALUES('".$username."','".$psd."','".$addtime."','".$email."','')";
		$result=mysqli_query($conn,$sql);
		echo "新增用户成功";
	}
}else{
    include('top.php');
?>
<div class="ngwlogin">
    <div class="formtitle">
        <a href="/">人才管理系统</a>
    </div>
    <div class="ngwform">
        <form class="form" action="" method="post">
            <input type="hidden" name="ispost" value="1">
            <div>
                <label>用户名</label>
                <input type="text" name="username" placeholder="请输入用户名(学号或手机号)" required="required" class="input" value="" />
            </div>
            <div>
                <label>邮箱</label>
                <input type="email" name="email" placeholder="请输入邮箱地址(用于找回密码)" required="required" class="input" value="" />
            </div>
            <div>
                <label>密码</label>
                <input type="password" name="psd" placeholder="请输入密码" required="required" class="input" value="" />
            </div>
            <ul>
                <li class="fl"><button type="submit">新增</button></li>
            </ul>
        </form>
    </div>
    <div class="formfoot"></div>
</div>
</body>
</html
<?php
}?>


userdel.php 删除用户

<?php
include('check.php');
$sql="delete from user where id=".$_GET['id'];
$s=mysqli_query($conn,$sql);
if($s){
	echo "删除成功";
}else{
	echo "删除失败";
}
?>


check.php 检查文件

<?php
include("conn.php");
if($_SESSION['username']){
	
}else{
	header("location:login.php");
}
?>


conn.php数据库连接文件

<?php
// 创建数据库连接
	$conn = mysqli_connect("localhost", "root", "root")or die("无法连接到数据库");
	mysqli_select_db($conn,"rencai") or die(mysqli_error($conn));
    mysqli_query($conn,'set NAMES utf8');
?>


index.php后台首页文件

<?php
include('check.php');
include('top.php');
?>


login.php后台登录

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="http://www.niuguwen.com/plugin/niuguwen/css/niuguwen.css">
<title>用户登录</title>
</head>
<body>
<div class="ngwlogin">
    <div class="formtitle">
        <a href="/">人才管理系统</a>
    </div>
    <div class="ngwform formbody">
        <form class="form" action="" method="post">
            <div>
                <label>用户名</label>
                <input type="text" name="username" placeholder="请输入用户名(学号或手机号)" required="required" class="input" value="" />
            </div>
            <div>
                <label>密码</label>
                <input type="password" name="psd" placeholder="请输入密码" required="required" class="input" value="" />
            </div>
            <ul>
                <li class="fl"><button type="submit">登录</button></li>
                <li class="fr">
                    <a href="register.php">注册</a> 
                </li>
            </ul>
        </form>
    </div>
    <div class="formfoot"></div>
</div>
</body>
</html>


loginout.php退出

<?php
session_destroy();
header("location:login.php")
?>


文章导航