Location: PHPKode > scripts > Simple Accounting System > SimpleAccounts/registration.php
<?php 
ob_start();
include_once 'lib.dbconnect.php' 
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="lib.global.css"/>
<script>
function validateEntries() 
{
	var reg = /[a-zA-Z]{1}[a-zA-Z0-9]{5,19}$/
	var str = document.getElementById("username").value;
	if (!(str.match(reg)))
	{
		document.getElementById("message").innerHTML = "Not a valid username. Please enter alpha numeric minimum of 6 characters and maximum of 20 characters and should start with alphabet.";
		return false;	
	}
	
	var reg = /^[A-Za-z]\w{6,}$/;
	var str = document.getElementById("pass").value;		
	if (!(str.match(reg)))
	{
		document.getElementById("message").innerHTML = "Please enter a valid password! password must be at least 8 characters long and start and end with a letter.";
		return false;	
	}	
	
	var pass = document.getElementById('pass').value;
	var pass2 = document.getElementById('pass2').value;
	var cname = document.getElementById('cname').value;
	
	if (pass != pass2){
		document.getElementById("message").innerHTML = "Please enter the confirmed password correctly.";
		return false;	
	}
	
	if (cname == ""){
		document.getElementById("message").innerHTML = "Please enter the Company Name / Individual Name .";
		return false;	
	}
	
	return true;
}
</script>
<style>
body {color:#2F2F2F}
.fieldsetform {border:1px solid #B4B4B4;margin:0 0 15px;padding:15px;}
.rowform {padding: 8px 0px;}
.rowform label {float:left;font-weight:bold;text-align:right;width:175px;padding: 0px 5px;}
</style>
</head>
<body>
<div id="maincontainer">
<?php
			include_once "header.php";		
			include_once 'lib.dbconnect.php';
?>

<div id="contentwrapper">
	<div id="contentcolumn">
	<div class="innertube"><?php 
		//This code runs if the form has been submitted
		
		if (isset($_POST['submit'])) 
		{
			
			mysql_select_db($main_database);
						
			//This makes sure they did not leave any fields blank
			if ($_POST['username'] == "" || $_POST['pass'] == "" || $_POST['pass2'] == "") 
			{
				$message = 'You did not complete all of the required fields';
			}

			// checks if the username is in use
			if (!get_magic_quotes_gpc()) {
				$_POST['username'] = addslashes($_POST['username']);
			}
			
			$usercheck = $_POST['username'];
			$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error());
			$check2 = mysql_num_rows($check);

			//if the name exists it gives an error
			if ($check2 != 0) {
				$message = 'Sorry, the username '.$_POST['username'].' is already in use.';
			}

			// this makes sure both passwords entered match
			if ($_POST['pass'] != $_POST['pass2']) {
				$message = 'Your passwords did not match.';		
			}

			// here we encrypt the password and add slashes if needed
			$_POST['pass'] = md5($_POST['pass']);
			if (!get_magic_quotes_gpc()) {
				$_POST['pass'] = addslashes($_POST['pass']);
				$_POST['username'] = addslashes($_POST['username']);
			}

			
			// now we insert it into the database
			$insert = "INSERT INTO users (username, password, cname) VALUES ('".$_POST['username']."', '".$_POST['pass']."','".$_POST['cname']."')";
			
			$add_member = mysql_query($insert);
			
			if ($add_member) 
			{
				$create_tables_query = "CREATE TABLE ".$_POST['username']."_account_name (".
				  "refid int(11) NOT NULL auto_increment,".
				  "acc_name varchar(30) NOT NULL default '',".
				  "acc_head enum('bs','tr','pl') NOT NULL default 'bs',".
				  "group_head enum('asset','liability','debit','credit') NOT NULL default 'asset',".
				  "other_details text,".
				  "act_group_head varchar(50) NOT NULL,".
				  "opening_balance bigint(15) default '0',".
				  "opening_balance_type enum('debit','credit') default NULL,".
				  "closing_balance bigint(15) default '0',".
				  "closing_balance_type enum('debit','credit') default NULL,".
				  "status char(1) default NULL,".
				  "backup char(1) default NULL, ".
				  "PRIMARY KEY  (refid)".
				") ENGINE=MyISAM DEFAULT CHARSET=latin1;";
				$create_tables_query1 = "CREATE TABLE ".$_POST['username']."_daybook (".
				  "refid int(10) NOT NULL auto_increment,".
				  "`dayBookDate` date NOT NULL default '0000-00-00',".
				  "debit varchar(50) NOT NULL default '',".
				  "credit varchar(50) NOT NULL default '',".
				  "dayBookContra enum('Y','N') NOT NULL default 'Y',".
				  "dayBookAmount double NOT NULL default '0',".
				  "description text NOT NULL,".
				  "status char(1) NOT NULL default '',".
				  "backup char(1) NOT NULL default '',".
				  "PRIMARY KEY  (refid)".
				  ") ENGINE=MyISAM DEFAULT CHARSET=latin1;";
 				//echo $create_tables_query;
				//$create_tables_result = mysql_query($create_tables_query);
				if (mysql_query($create_tables_query) && mysql_query($create_tables_query1))
				{
					echo "User Account : ".$_POST['username']." Created <br />";
					echo "<a href='login.php'>Click Here to Login</a>";
					//header ("Location: login.php?create=success");
				} else {
					echo "Problem in creating user accounts.";
				}
			}	
		} else {	
				
		}		
		?>
		<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
		
		<fieldset class="fieldsetform">
		<legend>Sign Up</legend>
		<div class="rowform">
			<label>* Username</label>
			<input type="text" name="username" id="username" maxlength="30">
		</div>
		<div class="rowform">
			<label>* Password</label>
			<input type="password" name="pass" id="pass" maxlength="20">
		</div>
		<div class="rowform">
			<label>* Confirm Password</label>
			<input type="password" name="pass2" id="pass2" maxlength="20">
		</div>
		<div class="rowform">
			<label>* Company Name / Individual Name</label>
			<input type="cname" name="cname" id="cname" maxlength="40">
		</div>
		<div class="rowform">
			<label>&nbsp;</label>
			<input type="submit" name="submit" onclick="javascript:return validateEntries()" value="Register" />
		</div>
		
		</fieldset>	
		</form>
		<div id="message"><?php echo $message; ?></div>
	</div>
</div>
</div>
	

<div id="leftcolumn">
	<div class="innertube_high">
		<b><a href="registration.php">New User Sign Up</a><em></em></b>
	</div>
	<div class="innertube">
		<b><a href="login.php">Login</a></b>
	</div>
</div>
	
</div><?php include_once 'footer.php' ?>
</div> 
<!-- End of Main Container -->
</body>
</html>
<?php ob_end_flush(); ?>
Return current item: Simple Accounting System