Location: PHPKode > projects > DataDivisions > includes/funcRegister.php
<?
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# DataDivisions, Build 1.0, 12/11/2003                                      #
# FileName: funcRegister.php                                                #
# File Description:                                                         #
#   Provides functions required for a user to register and setup login      #
#   credentials (back-end, middle and front-end)                            #
#                                                                           #
# +-----------------------------------------------------------------------+ #
# | DataDivisions - Website Statistic Visualization Software              | #
# | Copyright (c) 2003, Brian Willison                                    | #
# +-----------------------------------------------------------------------+ #
# | The contents of this file are subject to the GNU General Public       | #
# | License version 2 (June 1991). This file and all its contents (incl.  | #
# | functions, methods, etc.) are free for general use within any         | #
# | community. This software is distributed with the intent to allow      | #
# | developers the opportunity to copy, manipulate and revamp this        | #
# | application in part or whole for best use cases.                      | #
# |                                                                       | #
# | This software is distributed "AS-IS" with no warranties of any kind   | #
# | either expressed or implied.                                          | #
# |                                                                       | #
# | Please refer to the GPL license document for more information:        | #
# | (_docs/gplLicense.pdf)                                                | #
# +-----------------------------------------------------------------------+ #
# | Developer, Designer, Initial Creator:                                 | #
# | Brian Willison (hide@address.com)                       | #
# +-----------------------------------------------------------------------+ #
# | Initial Download Reference:                                           | #
# | http://datadivisions.sourceforge.net                                  | #
# +-----------------------------------------------------------------------+ #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

// Function: Check Register Form
function checkRegisterForm($_POST) {
	if ($_POST['username'] == "" || $_POST['password'] == "") {
		return "blankSubmit";
	} else {
		// Setup Db Connection 
		$dbOpen = dbConnect();
		$query = "SELECT * FROM ".dbTableUsers;
		$result = mysql_query($query);
		$numRows = mysql_num_rows($result);
		dbClose($dbOpen);
		// Check If UserName Already Exists
		for ($i=0; $i<$numRows; $i++) {
			$array = mysql_fetch_array($result);
			if ($array[0] == $_POST['username']) { 		// username found, so check password
				return "usernameAlreadyExists";			// username already exists in db
			}
		}
		// Check If Password and Password Confirmation Match Up
		if ($_POST['password'] != $_POST['passwordConfirm'])
			return "passwordsDontMatch";
		// UserName = Okay & Passwords Match, so Insert New User Into Db
		$username = $_POST['username'];
		$password = $_POST['password'];
		$dbOpen = dbConnect();
		$query = "INSERT INTO ".dbTableUsers." VALUES ('$username','$password')";
		$result = mysql_query($query);
		dbClose($dbOpen);
	}
}
// Function: Generate Register Form
function genRegisterForm($errorCheck) {
global $_POST;
	genAppSmHeader(pageName);
?>
	<tr>
	<td></td>
	<td valign="top" colspan="3"><p class="header">To activate your account, please fill in the form below choosing a username and password. 
	When you are finished, please click "Submit."</td>
	</td>
	</tr>
	<tr>
	<td valign="top" colspan="5"><?writeSpacer(1,10);?></td>
	</tr>
<?
	if ($errorCheck != 0) {
		printf("\t<tr><td></td><td valign=\"top\" colspan=\"3\"><p class=\"error\">%s</td><td></td></tr>",genErrorMsg($errorCheck));
	}
?>
	<tr>
	<td valign="top" colspan="5"><?writeSpacer(1,10);?></td>
	</tr>
	<tr>
	<form name="register" method="post" action="<?=phpSelf?>">
	<td></td>
	<td><p align="right">Username:</td>
	<td></td>
	<td><p><input type="text" name="username" size="25" maxlength="25" value="<?if(isset($_POST['username'])){echo$_POST['username'];}?>"></td>
	<td></td>
	</tr>
	<tr>
	<td></td>
	<td><p align="right">Password:</td>
	<td></td>
	<td><p><input type="text" name="password" size="25" maxlength="10" value=""></td>
	<td></td>
	</tr>
	<tr>
	<td></td>
	<td><p align="right">Confirm Password:</td>
	<td></td>
	<td><p><input type="text" name="passwordConfirm" size="25" maxlength="10" value=""></td>
	<td></td>
	</tr>
	<tr>
	<td valign="top" colspan="5"><?writeSpacer(1,10);?></td>
	</tr>
	<tr>
	<td></td>
	<td></td>
	<td></td>
	<td valign="top"><input type="submit" name="submit" value="Submit" class="btnSubmit"></td>
	<td></td>
	</form>
	</tr>
	<tr>
	<td valign="top" colspan="5"><?writeSpacer(1,15);?></td>
	</tr>
<?
	genAppSmFooter(pageName);
}
?>
Return current item: DataDivisions