Jump to content


Photo

registration script


  • Please log in to reply
2 replies to this topic

#1 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 30 October 2006 - 01:03 AM

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:
<?php
define("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();

?>


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 30 October 2006 - 01:32 AM

Thats because only one clause of an if elseif elese will be fullfilled. The first true expression.

You need to put each check in its own if. eg;

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";
}

PS: Sorry but, your code formatting (indentation) is terrible. See my example? No need to keep getting deeper and deeper.

#3 spfoonnewb

spfoonnewb
  • Members
  • PipPipPip
  • Advanced Member
  • 276 posts

Posted 30 October 2006 - 01:34 AM

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.

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";
						}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users