0

Alright, so I am working on this new site and for the registration, I am using a template I have used plenty of times in the past. Now, this one snippet I am showing you will check if the username is either too short or too long, or if the password fields do not match. Those are the parts that don't work. Notice how for each thing it appends more data on to the errorMsg variable.
It works for checking if the username/email is inside the database, but not for username length and password match.

if ((!$username) || (!$email) || (!$pass1) || (!$pass2)) { 

			$errorMsg .= "Please check the following:";

			if (!$username) {
				$errorMsg .= "<li>Please fill in your Username</li>";
				}

			if (!$email) {
				$errorMsg .= "<li>Please fill in your Email</li>";
				}

			} else if ($pass1 != $pass2) {
				$errorMsg .= "<li>Your Password fields below do not match</li>";
			} else if (strlen($username) < 4) {
				$errorMsg .= "<li>Your username is too short. 4 - 20 characters please</li>";
			} else if (strlen($username) > 20) {
				$errorMsg .= "<li>Your username is too long. 4 - 20 characters please</li>";
			} else if ($uname_check > 0){ 
				$errorMsg .= "<li>username in use</li>";
			} else if ($email_check > 0){ 
				$errorMsg .= "<li>email address in use</li>";
			} else { // Error handling is ended, process the data and add member to database

just want to know why the $pass1 != $pass2, strlen($username) < 4, and strlen($username) > 20 don't show up. I believe it is detecting the issue because it states "Please check the following:", but not the error.

2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by epicrevolt
0

And you should group your errors (username errors, email errors, password errors) and not all in one big IF-ELSE..

0

alright, I recoded it to group the parts together, now I have a different problem. It doesn't check anything! besides the recaptcha.

if(empty($username)) {
			$errorMsg .= "<li>Please fill in your username</li>";
		} elseif($uname_check > 0){ 
			$errorMsg .= "<li>Sorry, that username is already in our database</li>";
		} elseif((strlen($username) < 4) || (strlen($username) > 20)) {
			$errorMsg .= "<li>username must be etweeen 4-20 letters/numbers</li>";
			}

	if(empty($email)) {
			$errorMsg .= "<li>Please fill in your email address</li>";
		} elseif($email_check > 0){ 
			$errorMsg .= "<li>Sorry, that email address is already in our database</li>";
			}

	if((!$pass1) || (!$pass2)) {
			$errorMsg .= "<li>Please fill in both password fields correctly</li>";
		} elseif($pass1 != $pass2){ 
			$errorMsg .= "<li>both emails must match</li>";
			}

	if($errorMsg = "") { // Error handling is ended, process the data and add member to database

that's how it's all grouped right now. Just so you can have a closer look, take a look at: http://epicrevolt.com/zcomedy/site/register.php

0

I figured out the problem. It seems as though if you strip_tags before processing it destroys it. So I just used the htmlspecialchars and it works. here's my function.

function stripme($value) {//strip it good! make it ready for the database!
	$value = htmlspecialchars($value);
	$value = strip_tags($value);
	return $value;
	}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.