【发布时间】:2009-04-14 10:34:54
【问题描述】:
下面是我的游戏注册表单,它正在查找用户可能犯的错误,但即使发现错误,它也不会将其添加到$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);
}
}
【问题讨论】: