后台管理系统
后台管理系统四个主标题,分别为首页、成员管理、投票管理投票数据查看。
其中首页包括管理员设置和投票设置。
管理员设置主要功能是为了实现管理员密码的修改,具体代码如下:
<?php
include('../conn.php');
include('common.php');
if(@$_POST['oldpass']){
$oldpass = $_POST['oldpass'];
$newpass = $_POST['newpass'];
$newpass2 = $_POST['newpass2'];
$result = $db->query("select * from users where username='admin' and passwd='$oldpass'");
if($result->num_rows == 0){
echo "<script>onload = function(){document.getElementById('errortext').innerHTML='原始密码错误!';}</script>";
}else{
if($newpass != $newpass2){
echo "<script>onload=function(){document.getElementById('errortext').innerHTML='两次密码输入不一致';}</script>";
}else{
$result = $db->query("update users set passwd='$newpass' where username='admin'");
if($result){
echo "<script>onload = function(){document.getElementById('errortext').innerHTML='修改成功';}</script>";
}else{
echo "<script>onload = function(){document.getElementById('errortext').innerHTML='修改失败';}</script>";
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<link rel="stylesheet" href="css/add.css" type="text/css" media="screen" />
<link rel="stylesheet" href="utilLib/bootstrap.min.css" type="text/css" media="screen" />
</head>
<body>
<div class="div_from_aoto" style="width: 500px; margin:30px 40px;">
<div id="result111" class="result111" style="width:300px; height:20px; margin:4px auto; color:#33FF99; ">
<h5 id="errortext"></h5>
</div>
<FORM action="Adminset.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<DIV class="control-group">
<label class="laber_from">原密码</label>
<DIV class="controls" ><INPUT class="passwd" name="oldpass" type=password placeholder=" 请输入原密码"><P class=help-block></P></DIV>
</DIV>
<DIV class="control-group">
<LABEL class="laber_from">新密码</LABEL>
<DIV class="controls" ><INPUT class="passwd" name="newpass" type=password placeholder=" 请输入新密码">
<P class=help-block></P></DIV>
</DIV>
<DIV class="control-group">
<LABEL class="laber_from">重复密码</LABEL>
<DIV class="controls" ><INPUT class="passwd" name="newpass2" type=password placeholder=" 请输入新密码">
<P class=help-block></P></DIV>
</DIV>
<DIV class="control-group">
<LABEL class="laber_from" ></LABEL>
<DIV class="controls" ><button class="btn btn-success" style="width:120px;" >修改管理员密码</button></DIV>
</DIV>
</FORM>
</div>
</body>
</html>
上述代码只是简单的获取原密码,新密码和新密码的重新输入,获取之后对原密码进行检测,和新密码与新密码重新输入是否一致的检测。检测无误后对数据库的信息进行更新,这里在对普通用户和管理员的身份区别上是普通用户在admin项上为0,管理员则为1。
投票设置则主要是对投票的主题和投票的描述进行设置,具体代码如下:
<?php
include('../conn.php');
include('common.php');
if(@$_POST['votename']){
@$votename = $_POST['votename'];
$description = $_POST['description'];
$result = $db->query("update sysconfig set vote_name='$votename', description='$description' where cid='1';");
if($result){
echo "<script>onload = function(){document.getElementById('errortext').innerHTML='配置保存成功';}</script>";
}else{
echo "<script>onload = function(){document.getElementById('errortext').innerHTML='配置保存失败';}</script>";
}
}
if(@$_GET['do']=="reset"){
$r1 = $db->query("update sysconfig set vote_name='', method='1', description='' where cid='1';");
if($r1){
echo "<script>onload = function(){document.getElementById('errortext').innerHTML='投票信息清空成功';}</script>";
}else{
echo "<script>onload = function(){document.getElementById('errortext').innerHTML='投票信息清失败';}</script>";
}
}
$result = $db->query("select * from sysconfig where cid='1';");
$row = mysqli_fetch_assoc($result);
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/Calendar3.js"></script>
<link rel="stylesheet" href="css/add.css" type="text/css" media="screen" />
<link rel="stylesheet" href="utilLib/bootstrap.min.css" type="text/css" media="screen" />
</head>
<body>
<div class="div_from_aoto" style="width: 500px; margin:30px 40px;">
<div id="result111" class="result111" style="width:300px; height:20px; margin:4px auto; color:#33FF99;">
<h5 id="errortext"></h5>
</div>
<FORM action="Voteset.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<DIV class="control-group">
<label class="laber_from">投票主题</label>
<DIV class="controls" ><INPUT class="username" name="votename" type=text value="<?php echo $row['vote_name']; ?>"><P class=help-block></P></DIV>
</DIV>
<DIV class="control-group">
<label class="laber_from">投票描述</label>
<DIV class="controls" >
<textarea name="description" cols="" rows="" ><?php echo $row['description'];?></textarea>
<P class=help-block></P>
</DIV>
</DIV>
<DIV class="control-group">
<LABEL class="laber_from" ></LABEL>
<DIV class="controls" ><button class="btn btn-success" style="width:80px;" >保存配置</button>
<button class="btn btn-warning" style="width:80px;" type="button" onClick="location.href='Voteset.php?do=reset'" >重置投票</button>
</DIV>
</DIV>
</FORM>
</div>
</body>
</html>
这里也只是对各项内容的简单获取然后更新数据库信息并在投票页面呈现出来,而重置功能就是将所有数据更新为空白。
在成员管理中包括用户添加和用户管理,用户添加就是普通用户的注册,包括账号密码姓名和电话,具体代码如下:
<?php
include("common.php");
include("../conn.php");
if(@$_POST['username']){
@$user = $_POST['username'];
$pass = $_POST['passwd'];
$name = $_POST['name'];
$tel = $_POST['telephone'];
$result = $db->query("select username from users where username='$user';");
if($result->num_rows > 0){
echo "<script>onload = function(){document.getElementById('errortext').innerHTML='用户已存在';}</script>";
}else{
$result = $db->query("insert into users (username, passwd, admin , name,telephone) values ('$user', '$pass', '0' ,'$name','$tel');");
if($result){
echo "<script>onload = function(){document.getElementById('errortext').innerHTML='用户添加成功';}</script>";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<link rel="stylesheet" href="css/add.css" type="text/css" media="screen" />
<link rel="stylesheet" href="utilLib/bootstrap.min.css" type="text/css" media="screen" />
</head>
<body>
<div class="div_from_aoto" style="width: 500px; margin:30px 40px;">
<div id="result111" class="result111" style="width:300px; height:20px; margin:4px auto; color:#33FF99; ">
<h5 id="errortext"></h5>
</div>
<FORM action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<DIV class="control-group">
<label class="laber_from">用户名</label>
<DIV class="controls" ><INPUT class="username" name="username" type='text' placeholder=" 请输入用户名">
<P class=help-block></P></DIV>
</DIV>
<DIV class="control-group">
<LABEL class="laber_from">密码</LABEL>
<DIV class="controls" ><INPUT class="passwd" name="passwd" type='password' placeholder=" 请输入密码">
<P class=help-block></P></DIV>
</DIV>
<DIV class="control-group">
<LABEL class="laber_from">姓名</LABEL>
<DIV class="controls" ><INPUT class="name" name="name" type=text placeholder=" 请输入姓名">
<P class=help-block></P></DIV>
</DIV>
<DIV class="control-group">
<LABEL class="laber_from">电话</LABEL>
<DIV class="controls" ><INPUT class="telephone" name="telephone" type=text placeholder=" 请输入电话">
<P class=help-block></P></DIV>
</DIV>
<DIV class="control-group">
<LABEL class="laber_from" ></LABEL>
<DIV class="controls" ><button class="btn btn-success" style="width:120px;" >添加用户</button></DIV>
</DIV>
</FORM>
</div>
</body>
</html>
用户管理则是把普通用户的所有资料渲染出来,并能在此进行修改和删除,下面是源代码:
<?php
include("common.php");
include("../conn.php");
if(@$_GET['do'] == "delete"){
@$id = $_GET['id'];
$result = $db->query("delete from users where cid in ($id);");
if($result){
echo "<script>onload = function(){document.getElementById('errortext').innerHTML='删除成功';}</script>";
}else{
echo "<script>onload = function(){document.getElementById('errortext').innerHTML='删除失败';}</script>";
}
}
if(@$_POST['Submit']){
$id = $_POST['id'];
$passwd = $_POST['passwd'];
$name = $_POST['name'];
$telephone = $_POST['telephone'];
$result = $db->query("update users set passwd='$passwd',name='$name',telephone='$telephone' where cid='$id';");
if($result){
echo "<script>onload = function(){document.getElementById('errortext').innerHTML='修改成功';}</script>";
}else{
echo "<script>onload = function(){document.getElementById('errortext').innerHTML='修改失败';}</script>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<link rel="stylesheet" href="css/add.css" type="text/css" media="screen" />
<link rel="stylesheet" href="utilLib/bootstrap.min.css" type="text/css" media="screen" />
<script language="javascript">
function selectall()
{
var node = document.getElementsByName("checkboxitem");
for(var i=0; i<node.length;i++){
node[i].checked=true;
}
}
function unselectall(){
var node = d ocument.getElementsByName("checkboxitem");
for(var i=0; i<node.length;i++){
node[i].checked = false;
}
}
function deleteselect(){
var node = document.getElementsByName("checkboxitem");
id = "";
for(var i=0; i<node.length;i++){
if(node[i].checked){
if(id == ""){
id = node[i].value;
}else{
id = id+", "+node[i].value;
}
}
}
if(id == ""){
alert("请选择删除项");
}else{
location.href="?do=delete&id="+id;
}
}
</script>
</head>
<body>
<div class="div_from_aoto" style="width: 800px; margin:30px 40px;">
<div id="result111" class="result111" style="width:300px; height:20px; margin:4px auto; color:#33FF99; ">
<h5 id="errortext"></h5>
</div>
<form name="form1" method="post" action="">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>ID</td>
<td>用户名</td>
<td>姓名</td>
<td>电话</td>
<td>修改</td>
<td>删除</td>
</tr>
<?php
$result = mysqli_query($db,"select * from users where admin='0';");
while($row = mysqli_fetch_assoc($result)){
?>
<tr>
<td width="100" height="28" valign="middle"><input style="width:15px;" name="checkboxitem" type="checkbox" value="<?php echo $row['cid']; ?>"><?php echo $row['cid']; ?></td>
<td width="260"><?php echo $row['username']; ?></td>
<td width="260"><?php echo $row['name']; ?></td>
<td width="260"><?php echo $row['telephone']; ?></td>
<td width="*"><input style="width:40px; height:22px;" value="修改" type="button" onClick="location.href='?do=change&id=<?php echo $row['cid']; ?>'"></td>
<td width="34"><input style="width:40px; height:22px;" value="删除" type="button" onClick="location.href='?do=delete&id=<?php echo $row['cid']; ?>'"></td>
</tr>
<?php }?>
<tr>
<td colspan="4"><input value="选择全部" type="button" onClick="selectall()" />
<input value="取消全选" type="button" onClick="unselectall()" />
<input value="删除所选" type="button" onClick="deleteselect()" /></td>
</tr>
</table>
</form>
<?php
if(@$_GET['do'] == "change"){
$id = $_GET['id'];
$result = mysqli_query($db,"select * from users where cid='$id';");
$row = mysqli_fetch_assoc($result);
?>
<br/>
<div class="div_from_aoto" style="width: 800px;">
<form action="" method="post">
<input name="id" type="hidden" value="<?php echo $id; ?>">
<label>
<input name="" type="text" readonly="true" value="<?php echo $row['username']; ?>">
</label>
<label>
<input type="password" name="passwd" placeholder="输入新密码">
</label>
<label>
<input type="text" name="name" placeholder="输入新名字">
</label>
<label>
<input type="text" name="telephone" placeholder="输入新电话">
</label>
<label>
<input type="submit" name="Submit" value="修改">
</label>
</form>
</div>
<?php } ?>
</div>
</body>
</html>
这里要想渲染出普通用户的所有信息,则利用admin=0来获取普通用户的信息并全部渲染出来,这里利用$result = mysqli_query($db,"select * from users where admin='0';"); while($row = mysqli_fetch_assoc($result)){
。
若要删除用户,则@$_GET['do'] == "delete"
来获取要删除的用户,这里的do对应的是onClick="location.href='?do=delete&id=<?php echo $row['cid']; ?>'"
通过do=delect来获取该id,则为要删除用户的id。同理修改的功能也是一样,通过onClick="location.href='?do=change&id=<?php echo $row['cid']; ?>'">
来获取要修改的用户,修改则是将数据库的信息进行更新。
投票数据查看的源代码如下:
<?php
include ('../conn.php');
@session_start();
if( !isset($_SESSION['admin']) || !isset($_SESSION['user']) || ( $_SESSION['user']!== true && $_SESSION['admin']!== true ) ){
echo "<meta http-equiv=\"Refresh\" content=\"0;url=login.html\">";
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<link rel="stylesheet" href="css/add.css" type="text/css" media="screen" />
<link rel="stylesheet" href="utilLib/bootstrap.min.css" type="text/css"
media="screen" />
</head>
<body>
<div class="div_from_aoto" style="width: 80%; margin: 3em 4em; ">
<?php
$num = 0;
$result_name = $db->query ( "select * from votename1" );
while ( $row_name = mysqli_fetch_assoc ( $result_name ) ) {
$num += 1;
?>
<DIV class="control-group" style=" height: auto;">
<label class="laber_from" style="line-height: inherit; margin-bottom: 0;width:auto;"><?php echo $num.".".$row_name['question_name']; ?></label>
<br />
<?php
$result_option = $db->query ( "select * from voteoption1 where upid='" . $row_name ['cid'] . "';" );
$sumnum = $row_name['sumvotenum'];
while ( $row_option = mysqli_fetch_assoc ( $result_option ) ) {
?>
<DIV class="controls"
style=" float: left; width: 580px; margin: 2px 0 0 2em; clear: both;">
<div style="width: 280px; float:left;"><?php echo $row_option['optionname']; ?></div>
<div style="float:left;">
<div style="float:left; text-align:right; width:40px;"><?php echo $row_option['votenum'] ?>票</div>
<img src="../image/100.jpg" height="5" width="<?php echo $row_option['votenum']/$sumnum*100?>"/>
</div>
</DIV>
<?php } ?>
<div style="clear: both;"></div>
</DIV>
<?php } ?>
</div>
</body>
</html>
这里票数的长度条是用某个选项票数/所有票数*100来表示,即$row_option['votenum']/$sumnum*100
而所有的选项的呈现也是利用while ( $row_name = mysqli_fetch_assoc ( $result_name ) )