编辑不了用户,老师可以帮我一下。
<body>
<h3>编辑管理员</h3>
<form action="doAdminAction.php?act=editAdmin&id=<?php echo $id;?>" method="post">
<table width="70%" border="1" cellpadding="5" cellspacing="0"
bgcolor="#cccccc">
<tr>
<td align="right">管理员名称</td>
<td><input type="text" name="username" placeholder="<?php echo $row['username']?>" /></td>
</tr>
<tr>
<td align="right">管理员密码</td>
<td><input type="password" name="<?php echo $row['password']?>" /></td>
</tr>
<tr>
<td align="right">管理员邮箱</td>
<td><input type="text" name="email" placeholder="<?php echo $row['email']?>" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="编辑管理员" /></td>
</tr>
</table>
</form>
</body>
<?php
require_once '../core/admin.inc.php';
require_once '../lib/mysql.func.php';
$act=$_REQUEST['act'];
$id=$_REQUEST['id'];
if($act=="logout"){
logout();
}elseif ($act=="addAdmin"){
$mes=addAdmin();
}elseif ($act=="editAdmin"){
$mes=editAdmin($id);
}
?>
function editAdmin($id){
$arr=$_POST;
$arr['password']=md5($_POST['password']);
if(update("imooc_admin", $arr, "id={$id}")){
$mes="编辑成功!<a href='listAdmin.php'>查看管理员列表</a>";
}else{
$mes="编辑失败!<a href='editAdmin.php'>请重新修改</a>";
}
return $mes;
}
function update($table,$array,$where=null){
$line=mysqli_connect(DB_HOST,DB_USER,DB_PWD,DB_DBNAME);
foreach($array as $key=>$val){
if($str==null){
$sep="";
}else{
$sep=",";
}
$str.=$sep.$key."='".$val."'";
}
$sql="update {$table} set {$str} ".($where==null?null:" where ".$where);
$result=mysqli_query($line,$sql);
//var_dump($result);
//var_dump(mysql_affected_rows());exit;
if($result){
return mysqli_affected_rows($line);
}else{
return false;
}
}