Location: PHPKode > projects > NetLink > netlink_os/add_account.php
<h3>Add an Account</h3>
<?php
if (isset($submit))
{
	extract($_POST);
	$flag = 0;
	$name=$username;
  include("db.php");
	$dbh=mysql_connect ($host,$account,$acc_pw) or die (mysql_error());
	mysql_select_db ($table);
    $name=strtolower($f_name[0].$l_name);
	echo "<div id='tut'>";		
	if ($pw1==$pw2)
	{
		echo "&#8674;Checking existing accounts...";
		if(mkdir("Users/$name",0777))
		{
			chmod("Users/$name",0777);
				echo "<blockquote><i>No account named \"$name\" exists!</i></blockquote>";
			echo "&#8674;Creating account...";
			$flag=1;
			//Write account and password to database #############################
			echo "<blockquote>Connecting to Database...";
			//Insert the new account as a new row in the database
			
			#Insert new user into Accounts Table
                  $pw1=md5($pw1);
			$sql="INSERT INTO Accounts (Username, Password, FirstName, LastName, BDay, email) VALUES ('$name', '$pw1', '$f_name', '$l_name', '$BDay', '$email')";
			$rs=mysql_query($sql,$dbh);
			
			#Insert new user into CSS Table
			$sql="INSERT INTO CSS (Username, text, background, activelink, link, vlink, h1, h2) VALUES ('$name','000000','FFFFFF','0099FF','0000FF','FF0000','000000','000000')";
			$rs=mysql_query($sql,$dbh);
			#Insert new user into CSS Table
			$sql="INSERT INTO CSS_TEMP (Username, text, background, activelink, link, vlink, h1, h2) VALUES ('$name','000000','FFFFFF','0099FF','0000FF','FF0000','000000','000000')";
			$rs=mysql_query($sql,$dbh);
			# E x e c u t e   C o m m a n d # # # # # # # # # # # # # # # # # # #
			mysql_close($dbh);
			echo "<br/>Database Updated!";
			//End Database Commands ###############################################
			echo "<br/><i>Directory \"$name\" created!</i></blockquote>";
		}
		else
			echo "<span id='error'><br/><br/>ERROR: Directory already exists!</span><br/><br/>";	
	}
	else
	  echo "<span id='error'>Your passwords do not match.</span><br/><br/>";
}
	
if ($flag==1)
{
	echo "&#8674;Creating index.html in $name account...";
	
	if(!($f=fopen("Users/$name/index.html","w")))
		exit("Unable to open file.");
	while(!feof($f))
	{
		$x=fgets($f);
		echo $x;
		//HTML basics
		$code="<html>\n <head>\n <title>\n \n </title>\n <style type='text/css'>\n \n </style>\n </head>\n \n <body>\n \n \n \n \n \n \n </body>\n </html>";	
		
		fwrite($f,($code));
	}
	fclose($f);
	echo "<br/>Changing File Modification Codes...";
	
	chmod("Users/$name/index.html",0777);
	##################
	echo "&#8674;Creating CSS Theme in $name account...";
	if(!($f=fopen("Users/$name/www.css","w")))
		exit("Unable to open file.");
	while(!feof($f))
	{
		$x=fgets($f);
		echo $x;
		//HTML basics
		$code="/*Created on ".date("l, F jS, Y @ G:i")."*/";	
		
		fwrite($f,($code));
	}
	fclose($f);
	echo "<br/>Changing File Modification Codes...";
	
	chmod("Users/$name/www.css",0777);
	#################
	echo "<blockquote><i><b>$name/index.html created!</b></i></blockquote>";
	echo "</div>";
	echo "<h4>Account \"$name\" created!</h4>";
}

?>
Fill in the required fields below to create a new account
<form method='post' action='?id=add_account'>
<table summary='account' border='0'>
<tr>
<td>
Username:
</td>
<td>
<i>Automatically Created</i></td>
</tr>
<tr>
<td>
First Name:
</td>
<td>
<input type='text' name='f_name'/>
</td>
</tr>
<tr>
<td>
Last Name:
</td>
<td>
<input type='text' name='l_name'/>
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type='password' name='pw1'/>
</td>
</tr>
<tr>
<td>
Re-type Password:
</td>
<td>
<input type='password' name='pw2'/>
</td>
</tr>
<tr>
<td>
Birthdate (DDMMYYYY):
</td>
<td>
<input type='text' name='BDay'/>
</td>
</tr>
<tr>
<td>
Contact E-Mail:
</td>
<td>
<input type='text' name='email'/>
</td>
</tr>
<tr>
<td colspan='2'>
<input type='submit' name='submit' value='Create Account'/>
</td>
</tr>
</table>
</form>
Return current item: NetLink