below is my register form for my game and it is looking for errors that the user may have done, but even if an error is found it wont add it onto the $errors array. When I print_r the array it returns empty.
I believe something is going wrong with the if functions because if I add a value into the array from outside one of the if functions it adds it.
Here is my code:
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);
}
}