下面是我的遊戲註冊表格,它正在尋找用戶可能已經完成的錯誤,但即使發現錯誤,它也不會將其添加到$errors
陣列中。當我print_r
數組它返回空。數組總是回來爲空
我相信if函數有問題,因爲如果我從if函數之外添加一個值到數組中,它會添加它。
這裏是我的代碼:
if (isset($_GET['action'])){
db_connect();
db_select();
if ($_GET['action'] == "register"){
$username = $_POST['username'];
$password = $_POST['password'];
$confirm = $_POST['confirm'];
$email = $_POST['email'];
$agree = $_POST['agree'];
$errors = array();
if (!isset($username)){
$errors['0'] = "You did not specifiy a username";
}elseif (ereg("[^a-z0-9]", $username)) {
$errors_array['0'] = "Usernames can only contain lowercase letters and numbers";
}elseif (mysql_num_rows(mysql_query("SELECT username FROM users WHERE username = '{$username}'")) > 0) {
$errors['0'] = "The username you chose has already been taken";
}
if (!isset($password)){
$errors['1'] = "You did not specify a password";
}elseif ($password != $confirm){
$errors['1'] = "The password and password confirm fields do not match";
}
if (!isset($email)){
$errors['2'] = "You did not specify a E-mail address";
}elseif (mysql_num_rows(mysql_query("SELECT email FROM users WHERE email = '{$email}'")) > 0) {
$errors['2'] = "The E-mail you specified is already being used";
}
print_r($errors);
}
}
這是對問題的附錄(編輯)或對解決方案/問題的評論。但絕對不是答案。 – soulmerge 2009-04-15 07:39:44