修改管理员信息时,var_dump的语句id是空的
<?php require_once '../include.php'; header("content-type:text/html;charset=utf-8"); $id = $_REQUEST['id']; $sql = "select id,username,password,email from shop_admin where id='{$id}'"; $row = fetchOne($sql); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <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" value="<?php echo $row['username'];?>"/></td> </tr> <tr> <td align="right">管理员密码</td> <td><input type="password" name="password" value="<?php echo $row['password'];?>"/></td> <tr> <td align="right">管理员邮箱</td> <td><input type="text" name="email" value="<?php echo $row['email'];?>"/></td> </tr> <tr> <td colspan="2"><input type="submit" value="修改管理员"/></td> </tr> </table> </form> </body> </html>
/** * 修改管理员 */ function editAdmin($id){ $arr = $_POST; $arr['password'] = md5($_POST['password']); // $mes = update("shop_admin", $arr,"id = {$id}"); // var_dump($mes); // print_r($mes); if (update("shop_admin", $array,"id = {$id}")) { $mes = "修改成功! <br/><a href='listAdmin.php'>查看管理员</a>"; }else { $mes = "修改失败!<br/><a href='listAdmin.php'>重新修改</a>"; } return $mes; }
<?php require_once '../include.php'; header("content-type:text/html;charset=utf-8"); $act = $_REQUEST['act']; $id = $_REQUEST['id']; if($act == "logout"){ //注销 logout(); }elseif ($act == "addAdmin"){ //添加管理员 $mes = addAdmin(); }elseif ($act == "editAdmin") //编辑修改管理员 $mes = editAdmin($id); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <?php if ($mes){ echo $mes; }else { echo "操作失败!"; } ?> </body> </html>
/** * 更新操作 */ function update($table,$array,$where=null){ $link = connect(); foreach ((array)$sxh as $key => $val){ if ($str==null){ $sep=""; }else{ $sep=","; } $str = $sep.$key."='".$val."'"; } $sqli = "update {$table} set {$str}".($where==null?null:" where ".$where); mysqli_query($link, $sqli); var_dump($sqli); return mysqli_affected_rows($link); }
并且显示修改成功可是信息并没有修改