代码拉取完成,页面将自动刷新
同步操作将从 友人A/基于php的学生成绩管理系统(后台) 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<?php
include_once './config/config.php';
$LoginAdmin = auth();
if ($_POST) {
// 接收参数
$username = $_POST['username'];
$password = $_POST['password'];
$repass = $_POST['repass'];
if (!empty($_POST['checkUsername'])) {
$checkUsername = $_POST['checkUsername'];
$sql = "SELECT * FROM `stu_admin` WHERE username='$checkUsername'";
$res = mysqli_query($conn, $sql);
if ($res && mysqli_num_rows($res) > 0) {
echo json_encode(['msg' => '用户名已存在', 'code' => 0, 'data' => null]);
exit;
} else {
echo json_encode(['msg' => '用户名可以使用', 'code' => 1, 'data' => null]);
exit;
}
}
// 生成密码盐
$salt = build_ranstr();
// 封装数组
$data = [
'username' => $username,
'password' => md5($password.$salt),
'salt' => $salt
];
$avatar = upload_img('avatar');
if($avatar['code'] == 0)
{
ShowMsg($avatar['msg']);
}
$data['avatar'] = $avatar['data'];
$result = add('admin',$data);
if($result)
{
ShowMsg('新增管理员成功','adminlist.php');
}else{
ShowMsg('新增管理员失败');
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php include_once './common/meta.php'; ?>
<style>
input[type="file"] {
display: none;
}
label[for="avatar"] {
width: 200px;
}
</style>
</head>
<body>
<!--<![endif]-->
<?php include_once './common/header.php' ?>
<?php include_once './common/nav.php' ?>
<div class="content">
<div class="header">
<h1 class="page-title">添加管理员</h1>
</div>
<ul class="breadcrumb">
<li><a href="index.php">Home</a> <span class="divider">/</span></li>
<li><a href="adminlist.php">adminList</a> <span class="divider">/</span></li>
<li class="active">adminAdd</li>
</ul>
<div class="container-fluid">
<div class="row-fluid">
<div class="btn-toolbar">
<button class="btn btn-primary" onClick="location='adminlist.php'"><i class="icon-list"></i> 管理员列表</button>
<div class="btn-group">
</div>
</div>
<div class="well">
<div id="myTabContent" class="tab-content">
<div class="tab-pane active in" id="home">
<form method="post" enctype="multipart/form-data">
<label>用户名</label>
<input type="text" name="username" required class="input-xxlarge" placeholder="请输入用户名">
<span class="msg"></span>
<label>密码</label>
<input type="password" name="password" required class="input-xxlarge" placeholder="请输入密码">
<label>确认密码</label>
<input type="password" name="repass" required class="input-xxlarge" placeholder="请输入确认密码">
<span class="msg2"></span>
<label>头像</label>
<label for="avatar">
<img src="assets/images/upload.png" id="upload" alt="">
</label>
<input type="file" name="avatar" id="avatar" class="input-xxlarge">
<label></label>
<input class="btn btn-primary" type="submit" value="提交" />
</form>
</div>
</div>
</div>
<?php include_once('common/footer.php'); ?>
</div>
</div>
</div>
<?php include_once './common/script.php' ?>
</body>
</html>
<script>
$('#avatar').change(function() {
// console.log($(this));
// console.log(this.files[0]);
// 获取当前的文件
var file = this.files[0] || {}
// 返回对象地址
var url = GetObjectURL(file)
// // 把图像更新
$('#upload').attr('src', url)
})
$("[name='username']").change(function() {
$.ajax({
url: 'adminadd.php',
type: 'post',
dataType: 'json',
data: {
checkUsername: $(this).val()
},
success(res) {
if (res.code) {
$('.msg').css({
color: 'green'
}).html(res.msg)
} else {
$('.msg').css({
color: 'red'
}).html(res.msg)
}
},
erorr(err) {
console.log('err', err);
}
})
})
$("[name='repass']").change(function() {
if ($("[name='password']").val() != $(this).val()) {
$('.msg2').css({
color: 'red'
}).html('密码不一致')
}else{
$('.msg2').html('')
}
})
// $('[name="username"]').change(function() {
// $.post("adminadd.php", {
// username: $(this).val(),
// action: 'usernameajax',
// }, function(res) {
// // console.log(res);
// if (res.code) {
// $('.msg').css({
// color: 'green'
// }).html(res.msg)
// } else {
// $('.msg').css({
// color: 'red'
// }).html(res.msg)
// }
// }, "json")
// })
</script>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。