急!??!添加用戶失敗
King老師,注冊用戶為什么只講了靜態頁面修改,實際的注冊用戶函數都沒講就完了啊,另外根據教程,將注冊的函數拷貝到后臺添加用戶的admin.inc.php中,并跟著教程修改了,為什么添加用戶老是失敗,截圖如下:

注冊用戶函數:
/**
?*?添加用戶的操作
?*?@param?int?$id
?*?@return?string
?*/
function?addUser(){
$arr=$_POST;
$arr['password']=md5($_POST['password']);
$arr['regTime']=time();
$uploadFile=uploadFile("../uploads");
if($uploadFile&&is_array($uploadFile)){
$arr['face']=$uploadFile[0]['name'];
}else{
return?"添加失敗<a?href='addUser.php'>重新添加</a>";
}
if(insert("imooc_user",?$arr)){
$mes="添加成功!<br/><a?href='addUser.php'>繼續添加</a>|<a?href='listUser.php'>查看列表</a>";
}else{
$filename="../uploads/".$uploadFile[0]['name'];
if(file_exists($filename)){
unlink($filename);
}
$mes="添加失敗!<br/><a?href='addUser.php'>重新添加</a>|<a?href='listUser.php'>查看列表</a>";
}
return?$mes;
}注冊頁面:
<!doctype?html> <html> <head> ????<meta?charset="UTF-8"> ????<title>Document</title> </head> <body> <h3>添加用戶</h3> <form?action="doAdminAction.php?act=addUser"?method="post"?enctype="multipart/form-data"> <table?width="70%"?border="1"?cellpadding="5"?cellspacing="0"?bgcolor="#cccccc"> <tr> <td>用戶名</td> <td><input?type="text"?name="username"?placeholder="請輸入管理員名稱"/></td> </tr> <tr> <td>密碼</td> <td><input?type="password"?name="password"?/></td> </tr> <tr> <td>郵箱</td> <td><input?type="text"?name="email"?placeholder="請輸入管理員郵箱"/></td> </tr> <tr> <td>性別</td> <td><input?type="radio"?name="sex"?value="1"?checked="checked"/>男 <input?type="radio"?name="sex"?value="2"?/>女 <input?type="radio"?name="sex"?value="3"?/>保密 </td> </tr> <tr> <td>頭像</td> <td><input?type="file"?name="myFile"?/></td> </tr> <tr> <td?colspan="2"><input?type="submit"??value="添加用戶"/></td> </tr> </table> </form> </body> </html>
doAdminAction.php:
<?php
require_once?'../include.php';
$act?=?$_REQUEST['act'];
$id?=?@$_REQUEST['id'];
if?($act=="logout"){
????logout();
}elseif?($act=="addAdmin"){
????$mes?=?addAdmin();
}elseif?($act=="editAdmin"){
????$mes?=?editAdmin($id);
}elseif?($act=="delAdmin"){
????$mes?=?delAdmin($id);
}elseif?($act=="addCate"){
????$mes?=?addCate();
}elseif?($act=="editCate"){
????$where?=?"id={$id}";
????$mes?=?editCate($where);
}elseif??($act=="delCate"){
????$mes?=?delCate($id);
}elseif?($act=="addPro"){
????$mes?=?addPro();
}elseif?($act=="editPro"){
????$mes?=?editPro($id);
}elseif?($act=="delPro"){
????$mes?=?delPro($id);
}elseif?($act=="addUser"){
????$mes?=?addUser();
}
?>
<!doctype?html>
<html>
<head>
????<meta?charset="UTF-8">
????<title>Document</title>
</head>
<body>
<?php
????if($mes){
????????echo?$mes;
????}
?>
</body>
</html>
2016-01-06
問題可能出在insert那里,可以在insert方法里進行斷點調試echo ?die;就知道問題出在哪了
2016-01-06
insert("imooc_user",?$arr)你看下這個函數執行的結果是什么樣的呢?這個函數最好也貼上來,感覺要是出錯的話,應該就在這個函數里面