localhost Posted October 30, 2006 Share Posted October 30, 2006 My registration script is only showing one error if there is one or more errors.this is the script, thanks for any help you can provide:[code]<?phpdefine("IN_OMEGA", true);$omega_root_path = "./";include($omega_root_path."base.php");if (isset($_POST['submit'])) { $username = htmlspecialchars(trim($_POST['username'])); $password = md5(crypt(htmlspecialchars(trim($_POST['password'])), strlen($_POST['password']))); $confpass = md5(crypt(htmlspecialchars(trim($_POST['confpass'])), strlen($_POST['confpass']))); $email = htmlspecialchars(trim($_POST['email'])); $errors = array(); if (empty($username)) { $errors[] = "Username field is empty"; } elseif (empty($password)) { $errors[] = "Password field is empty"; } elseif ($password!=$confpass) { $errors[] = "Passwords do not match"; } elseif (empty($email)) { $errors[] = "E-Mail Address field is empty"; } $error_count = sizeof($errors); $error_phrase = (($error_count)==1) ? "<strong>There was a problem with your registration attempt:</strong><br />" : "<strong>There were some problems with your registration attempt:</strong><br />"; if (($error_count)==0) { $create_user = sql_query("INSERT INTO " . USERS_TABLE . " (`user_groupid`, `username`, `password`, `email`, `login_key`, `reg_date`, `reg_ip`, `user_lastactivity`) VALUES ('" . $sitedata['default_ugid'] . "', '" . $username . "', '" . $password . "', '" . $email . "', '" . crypt($username, rand(15,3648)) . "', '" . mktime() . "', '" . $_SERVER['REMOTE_ADDR'] . "', '" . mktime() . "')"); } else { echo $error_phrase; foreach ($errors as $error) { echo "-" . $error . "<br />"; } } }$template = new template("templates/" . $sitedata['template_dir'] . "/register.tpl");$template->output();?>[/code] Link to comment https://forums.phpfreaks.com/topic/25535-registration-script/ Share on other sites More sharing options...
trq Posted October 30, 2006 Share Posted October 30, 2006 Thats because only one clause of an [i]if elseif elese[/i] will be fullfilled. The first true expression.You need to put each check in its own if. eg;[code=php:0]if (empty($username)) { $errors[] = "Username field is empty";}if (empty($password)) { $errors[] = "Password field is empty";}if ($password != $confpass) { $errors[] = "Passwords do not match";}if (empty($email)) { $errors[] = "E-Mail Address field is empty";}[/code]PS: Sorry but, your code formatting (indentation) is terrible. See my example? No need to keep getting deeper and deeper. Link to comment https://forums.phpfreaks.com/topic/25535-registration-script/#findComment-116526 Share on other sites More sharing options...
spfoonnewb Posted October 30, 2006 Share Posted October 30, 2006 Try changing the elseif's to ifs..When you use elseif, once it matches one "if" is done it gives up/stops, as far as I know.Just a guess.[code] if (empty($username)) { $errors[] = "Username field is empty"; } if (empty($password)) { $errors[] = "Password field is empty"; } if ($password!=$confpass) { $errors[] = "Passwords do not match"; } if (empty($email)) { $errors[] = "E-Mail Address field is empty"; }[/code] Link to comment https://forums.phpfreaks.com/topic/25535-registration-script/#findComment-116528 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.