Jump to content

error in php register script


trektech

Recommended Posts

hey guys i have an error in my php script. when i load it up in the browser i get this error.

 

Parse error: parse error in C:\xampp\htdocs\php website\register.php on line 83

 

and i looked on line 83 and heres what i put

 

$range2 = (1,64);

 

 

what could possibly be wrong?

 

 

Link to comment
https://forums.phpfreaks.com/topic/162000-error-in-php-register-script/
Share on other sites

i am trying to make a register form that piece of script just limits the amount of characters people can use

 

heres a copy of the script

 

<?php

/**
* @author 
* @copyright 2009
*/

include_once "functions.php";

connect();

if($_POST['submit']){
 echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";
 echo "<form method=\"post\" action=\"register.php\">n";
echo "<tr><td> colspan=\"2\" align=\"center\">Registration Form</td><\tr>\n";
echo "<tr><td>Username</td><td><input type=\"text\" name=\"username\"></td></tr>\n";
	echo "<tr><td>Password</td><td><input type=\"password\" name=\"password\"></td></tr>\n";
		echo "<tr><td>Confirm</td><td><input type=\"password\" name=\"passconf\"></td></tr>\n";
			echo "<tr><td>E-Mail</td><td><input type=\"text\" name=\"email\"></td></tr>\n";
				echo "<tr><td>Name</td><td><input type=\"text\" name=\"name\"></td></tr>\n";
					echo "<tr><td>AIM Adress</td><td><input type=\"text\" name=\"aim\"></td></tr>\n";
echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Register\"></td></tr>\n";


}else{
$username = protect ($_POST['username']);
$password = protect ($_POST['password']);
$confirm = protect ($_POST['passconf']);
$email = protect($_POST['email']);
$name = protect ($_POST['name']);
$aim = protect ($_POST['aim']); 

$errors = array();

	if(!$username){
		$errors[] = "Please enter a username";

	}
	if(!$password){
		$errors = "Please enter a password";

	}

	if($password){
		if(!$confirm){
			$errors = "Please confirm your password";
		}
	}

	if(!$email){
		$errors = "Please enter your email adress";
	}

	if(!$name){
		$errors = "Please enter a name";
	}

	if($username){
		if(!ctype_alnum($username)){
			$errors = "Username can only contain letters and numbers";
			$range = range(6,32);
			if(!in_array(strlen($username),$range)){
				$errors = "Username must be between 6-32 characters";
			}
		}
	}

	if($password && $confirm){
		if($password != $confirm){
			$errors = "Passwords do not match";
		}
	}

	if($email){
		$checkemail = "/[a-z09]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-Z0-9]+)*)+\\.[a-z]{2,}$/i";
		if(!prg_mach($checkmail,$email)){
			$errors = "Emailis not vailid,must be [email protected]";
		}

	}

	if($name){
		$range2 = (1,64);
		if(!if_array(strlen($name),$range2)){
			$errors = "Your name must be between 3 and 64 characters";
		}
	}

	if($name){
		$range3 = (3,16);
		if(!if_array(strlen($name),$range3)){
			$errors = "Your aim name must be between 3 and 16 characters";
		}
	}

	if($username){
		$sql = "SELECT * FROM `users` WHERE `username`='{$username}'";
		$res = mysql_query($sql) or die(mysql_error());

			if(mysql_num_rows($res) > 0){
				$errors = "The username you supplied is already in use";
			}
	}

	if($email){
		$sql2 = "SELECT * FROM `users` WHERE `email`='{$email}'";
		$res2 = mysql_query($sql2) or die(mysql_error());

		if(mysql_num_rows($res2) > 0){
			$errors = "The email adress you supplied is already in use";
		}
	}

			if($aim){
		$sql2 = "SELECT * FROM `users` WHERE `aim`='{$aim}'";
		$res2 = mysql_query($sql2) or die(mysql_error());

		if(mysql_num_rows($res2) > 0){
			$errors = "The AIM email adress you supplied is already in use";
		}
	}

	if(count($errors > 0)){
		foreach($errors AS $errors){
			echo $errors . "<br>\n";
		}

	}else {
		$sql4 = "INSTERT INTO `users
		(`username`,`password`,`email`,`name`,`aim`)
		('$username','".md5($password)."',")"','$name','$aim');";

		$res4 = mysql_query(sql4) or die(mysql_error());
		echo "You have successfuly registered with the username <b>{$username}";

	}


}

?>

 

their might be more than that error in there but I'm bad at php. can you sort out my problem now?

 

I think you mean to use,

 


if ( strLen($name) < 3 || strLen($name) > 64 )
{
   $errors =  'Username can only be 3-64 characters (inclusive).';
}
else
{

 

//Edit.

 

Also your errors are simply being assigned to a single string value, if you wish to use them like that you need to do something like this:

 


if ( strLen($name) < 3 || strLen($name) > 64 )
{
   $errors[] =  'Username can only be 3-64 characters (inclusive).';
}

   if ( count ($errors) > 0 )
   {
      forEach ( $errors As $err )
      {
         echo '<span style="color: #ff0000;">' . $err . '</span><br >';
      }
   } 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.