Location: PHPKode > projects > Crown of Evanion > final/register.php
<?php
/*
*   This file is part of 'Crown of Evanion'.
*
*    'Crown of Evanion' is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    'Crown of Evanion' is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with 'Crown of Evanion'; if not, write to the Free Software
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
$title = "Register";
include("include.php");

if(! $page) {
	$error = $_REQUEST['error'];
	
	$errors = array(
		'0' => "<h5>Sorry, but it appears that your username is taken.</h5>", 
		'1' => "<h5>You did not enter a username.</h5>", 
		'2' => "<h5>You did not fill in both password fields.</h5>", 
		'3' => "<h5>Your passwords do not match.</h5>", 
		'4' => "<h5>You did not enter an e-mail address.</h5>",
		'5' => "<h5>You did not enter your strength.</h5>", 
		'6' => "<h5>You did not enter your toughness.</h5>",
		'7' => "<h5>You did not enter your intelligence.</h5>", 
		'8' => "<h5>You did not enter numbers for your strength, toughness, or intelligence.</h5>",
		'9' => "<h5>The sum of your strenght, toughness, and intellegence does not equal 10.</h5>",
		'10' => "<h5>You did not name your dragon.</h5>",
		'11' => "<h5>That is not a valid gender.</h5>",
		'12' => "<h5>That is not a valid color.</h5>",
		'13' => "<h5>Sorry, but the name you have chosen for your dragon is taken!</h5>",
		'14' => "<h5>Username must only contain letters, numbers, and underscores.</h5>",
		'15' => "<h5>Invalid E-mail address!</h5>",
		'16' => "<h5>Enter a positive value.</h5>",
		'17' => "<h5>Enter a positive value.</h5>",
		'18' => "<h5>Enter a positive value.</h5>",
		);	
	
	echo "
	<h2 id=\"pagetitle\">Registration</h2>

	<p>Interested in becoming a CyberPets member? All you need to do is fill out this page of information. Just make sure that your <strong>strength, toughness, and intelligence</strong> add up to <strong>10</strong>.</p>
	$errors[$error]
	<form action=\"$PHP_SELF\" method=\"POST\">
	<input type=\"hidden\" name=\"page\" value=\"proc1\">
	<div class=\"section reg\">
	<h3>User Information</h3>
	<table>
	<tr>
	<th scope=\"row\">Username</th>
	<td><input type=\"text\" name=\"user\" maxlength=\"12\"></td>
	</tr>
	
	<tr>
	<th scope=\"row\"><label for=\"passa\">Password</label></th>
	<td><input type=\"password\" name=\"passa\" id=\"passa\"></td>
	</tr>
	<tr>
	<th scope=\"row\"><label for=\"passb\">Repeat Password</label></th>
	<td><input type=\"password\" name=\"passb\" id=\"passb\"></td>
	</tr>
	<tr>
	<th scope=\"row\"><label for=\"mail\">E-mail</label></th>
	<td><input type=\"text\" name=\"mail\" id=\"mail\"></td>
	</tr>
	<tr>
	<th scope=\"row\"><label for=\"stre\">Strength</label></th>
	
	<td><input type=\"text\" name=\"stre\" id=\"stre\" size=\"3\"></td>
	</tr>
	<tr>
	<th scope=\"row\"><label for=\"tough\">Toughness</label></th>
	<td><input type=\"text\" name=\"tough\" id=\"intel\" size=\"3\"></td>
	</tr>
	<tr>
	<th scope=\"row\"><label for=\"intel\">Intelligence</label></th>
	<td><input type=\"text\" name=\"intel\" id=\"intel\" size=\"3\"></td>
	</tr>
	</table>
	</div>
	
	<div class=\"section reg\">
	<h3>Dragon Information</h3>
	<table>
	<tr>
	<th scope=\"row\"><label for=\"name\">Name</label></th>
	<td><input type=\"text\" name=\"name\" id=\"name\" maxlength=\"12\"></td>
	</tr>
	<tr>
	<th scope=\"row\"><label for=\"gender\">Gender</label></th>
	<td><select name=\"gender\" id=\"gender\">
	<option value=\"male\">Male</option>
	<option value=\"female\">Female</option>
	</select></td>
	</tr>
	<tr>
	</tr>
	</table>
	</div>
	<p><input type=\"submit\" value=\"Proceed\"></p>
	</form>
	";
}

if($page == "proc1") {
	$user = $_POST['user'];
	$passa = md5($_POST['passa']);
	$passb = md5($_POST['passb']);
	$mail = $_POST['mail'];
	$stre = round($_POST['stre']);
	$tough = round($_POST['tough']);
	$intel = round($_POST['intel']);
	$total = $stre + $tough + $intel;
	$name = $_POST['name'];
	$gender = $_POST['gender'];	
	
	$select = mysql_query("SELECT id FROM users WHERE username = '$user'");
	$num = mysql_num_rows($select);
	$select = mysql_query("SELECT id FROM dragons WHERE name = '$name'");
	$nub = mysql_num_rows($select);
	
	//$user = str_replace(" ","",$user);
	
	if($num > 0) {
		header("location: $PHP_SELF?error=0");
	}
	else if(! $user) {
		header("location: $PHP_SELF?error=1");
	}
	else if(! $passa) {
		header("location: $PHP_SELF?error=2");
	}
	else if(! $passb) {
		header("location: $PHP_SELF?error=2");
	}
	else if($passa != $passb) {
		header("location: $PHP_SELF?error=3");
	}
	else if(! $mail) {
		header("location: $PHP_SELF?error=4");
	}
	else if(! $stre) {
		header("location: $PHP_SELF?error=5");
	}
	else if(! $tough) {
		header("location: $PHP_SELF?error=6");
	}
	else if(! $intel) {
		header("location: $PHP_SELF?error=7");
	}
	else if(! ereg('[0-9]',$total)) {
		header("location: $PHP_SELF?error=8");
	}
	else if($total != 10) {
		header("location: $PHP_SELF?error=9");
	}
	else if(! $name) {
		header("location: $PHP_SELF?error=10");
	}
	else if(! $gender) {
		header("location: $PHP_SELF?error=11");
	}
	else if($nub > 0) {
		header("location: $PHP_SELF?error=13");
	} 
	else if(ereg('[^A-Za-z0-9_]',$user)) {
		header("location: $PHP_SELF?error=14");
	} 
	else if($stre < 0) {
		header("location: $PHP_SELF?error=16");
	} 
	else if($intel < 0) {
		header("location: $PHP_SELF?error=16");
	} 	
	else if($tough < 0) {
		header("location: $PHP_SELF?error=16");
	} else {
		echo "<h3>Registration Complete!</h3>
		Thank you for registering, you may now log in and see your egg. It should hatch in three hours, tops. Have fun!";
		
		$mana = round($intel * 2.5);
		$user = strip_tags($user);
		$passa = strip_tags($passa);
		$mail = strip_tags($mail);
		$name = strip_tags($name);
		$gender = strip_tags($gender);
		$hatch =	rand(5400,10800);
		$hatched = $timeofu + $hatch;
		
		
		$ran = rand(1,8);
		$color = array(4, 4, 4, 3, 3, 1, 1, 2,);
		
		mysql_query("INSERT INTO users (username,password,ip,regtimeU,regtimeR,tough,strength,intelligence,mana,maxmana,email,dragon) VALUES ('$user','$passa','$REMOTE_ADDR','$timeofu','$date','$stre','$tough','$intel','$mana','$mana','$mail','$name')") or die("Error- " . mysql_error());
		mysql_query("INSERT INTO dragons (name,owner,gender,color,life,hatch,hatched,created) VALUES ('$name','$user','$gender','$color[$ran]','$timeofu','$hatch','$hatched','$timeofu')") or die("Error - " . mysql_error());
	}
	

}
		
		
include("footer.php");
?>
Return current item: Crown of Evanion