Location: PHPKode > projects > JobAppr > Jobappr-1.4/admin/xx_register.php
<?php
session_start();
if(isset($_SESSION['password'])){
	header("Location: dashboard.php");
	exit();
}
require_once('../includes/functions.php');
require_once('inc/admin-functions.php');

if(isset($_POST['submit'])) {
	$error = null;
	$email = clean($_POST['email']);
	$username = clean($_POST['username']);
	$password_plain = $_POST['password']; 
	$password_confirm = $_POST['password_confirm']; 
	$last_name = clean($_POST['last_name']);
	$first_name = clean($_POST['first_name']);

	if (!isset($_POST['password']) || !isset($_POST['password_confirm']) || !isset($_POST['username']) || !isset($_POST['email']) || !isset($_POST['first_name']) || !isset($_POST['last_name'])) {
		$error .= "All fields are required<br />";
	}
	
	$sql="SELECT user_id FROM ". TB_USERS ." WHERE email='". $email ."'";
	$result=mysql_query($sql);
	$count=mysql_num_rows($result);
	if($count == 1){
		$error .= "This email address is already registered<br />";
	}
	
	$sql1="SELECT user_id FROM ". TB_USERS ." WHERE username='". $username ."'";
	$result1=mysql_query($sql1);
	$count1=mysql_num_rows($result1);
	if($count1 == 1){
		$error .= "This user name is already taken<br />";
	}
	
	if ($password_plain != $password_confirm) {
		$error .= "Passwords do not match<br />";
	}

	if(!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9.\+=_-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $_POST['email'])) {
	  $error .= 'Please enter a valid email address';
	}
	
	if(!$error){
		$password = phash($password_plain);
		$insert = "INSERT INTO ". TB_USERS ." VALUES (
	  		NULL,
	  		'".$username."',
	  		'".$email."',
	  		'".$password."',
	  		'".$first_name."',
	  		'".$last_name."',
	  		2,
	  		NULL,
			)";
		$status = mysql_query($insert);
		if ($status) {
			header("Location: dashboard.php");
			exit();
		} else {
			$error = 'Uh oh, the database connection failed'. mysql_error();
		}
	}
}

?>
<?php get_template('header', 'Registration'); ?>
	
	<div id="main">
		<?php display_messages(); ?>
		
		<h1>Registration</h1>
		
		<form id="registration" method="post" action="<?php echo get_filename(); ?>" >
			<table>
				<tr>
					<td class="label"><label for="first_name">Name</label></td>
					<td><input type="text" class="text double" id="first_name" name="first_name" value="<?php echo $first_name; ?>" /><em>First</em></td>
					<td><input type="text" class="text double" id="last_name" name="last_name" value="<?php echo $last_name; ?>" /><em>Last</em></td>
				</tr>
				<tr>
				<tr>
					<td class="label"><label for="email">Email Address</label></td>
					<td colspan="2"><input type="text" class="text" id="email" name="email" autocomplete="off" value="<?php echo $email; ?>" /></td>
				</tr>
				<tr>
					<td class="label"><label for="username">Username</label></td>
					<td colspan="2"><input type="text" class="text" id="username" name="username" autocomplete="off" value="<?php echo $username; ?>" /></td>
				</tr>
				<tr>
					<td class="label"><label for="password">Password</label></td>
					<td><input type="password" class="text double" id="password" name="password" autocomplete="off" value="" /><em>Password</em></td>
					<td><input type="password" class="text double" id="password_confirm" name="password_confirm" autocomplete="off" value="" /><em>Confirm Password</em></td>
				</tr>
				<tr>
					<td colspan="3"><input type="submit" class="submit" name="submit" value="Register" /></td>
				</tr>
			</table>
			
		</form>
		<p class="hint" ><a href="./">Login</a> &nbsp;|&nbsp; <a href="./reset.php">Reset Password</a></p>
			
	</div>


<?php get_template('footer'); ?>
Return current item: JobAppr