修改管理員信息時,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); }
并且顯示修改成功可是信息并沒有修改
2017-03-09
你看看輸出的
sql語句就知道 ?Id值和要修改的內容沒有傳遞進入?
?update語法
$sql = "update shop_admin set username='a' wherre id =1 ";
你自己再看看哪里錯了吧?。。。。?!