Aşağıda benim oyun için benim kayıt formu ve kullanıcı yapmış olabilir, ama bir hata bulunursa bile alışkanlık $errors
dizinin üzerine eklemek hataları arıyor. I print_r
dizisi boş döner.
Bir şey yanlış gidiyor inanıyorum eğer fonksiyonları çünkü dışarıdan gelen biri diziye bir değer eklerseniz onu ekler işlevleri eğer.
İşte benim kod:
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);
}
}