<html> 
<head> 
<title>Register</title> 
</head> 
<body> 

<?php 
$datafile = 'data.txt'; 

if($_GET['action'] == 'signup') { 
     
    if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['url']) || !isset($_POST['username']) || !isset($_POST['password'])){ 
        
        error_message('One or more required fields were left blank!', $_POST['name'], $_POST['email'], $_POST['url'], $_POST['username'], $_POST['password']); 
    } 
    
    $file = file($datafile); 
    while(list(,$value)=each($file)){  //check if user exists
        list($fname,$femail,$fuser,$fpass,$blank)=split( "\|", $value); 
        if($username==$fuser){ 
            
            error_message('Username is allready in use.', $_POST['name'], $_POST['email'], $_POST['url'], $_POST['username'], $_POST['password']); 
        } 
    } 
    
    $fp = fopen($datafile, 'a'); 
    fwrite($fp, $_POST['name'] . '|' . $_POST['email'] . '|' . $_POST['username'] . '|' . $_POST['password'] . "|\n"); 
    fclose($fp); 
    //html for sucessfull signup
?> 

</body>
</html>

<?php 
} else { 
 //html for sign up
?> 

<html>
<head>
<title>Register</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" TYPE="text/css">
</head>
<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">


<FORM action="<?php echo $_SERVER['file:///C|/Documents and Settings/KnightTony/??????/Website works/users/PHP_SELF']; ?>?action=signup" method="post"> 

<p>Name: 
  <INPUT type="text" name="name"></p> 

<p>E-mail Address: 
    <INPUT type="text" name="email"> </p>

<p>Website Address: 
    <INPUT type="text" name="url"> </p>

<p>Desired Username: 
    <INPUT type="text" name="username"> </p>

<p>Password: 
    <INPUT type="password" name="password"> </p>

<INPUT type="submit" value="Sign-up"> 
</FORM> 
</body>
</html>


<?php 
} 
function error_message($message, $name, $email, $url, $username, $password) { 
?> 

<html>
<head> //html for signing up error
<title>Error</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" TYPE="text/css">
</head>
<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

			<?php echo $message;?> //error message

<FORM action="<?php echo $_SERVER['file:///C|/Documents and Settings/KnightTony/??????/Website works/users/PHP_SELF']; ?>?action=signup" method="post">
 
<P>Name: <INPUT type="text" name="name" value="<?php echo $name;?>"> 

<P>E-mail Address: <INPUT type="text" name="email" value="<?php echo $email;?>"> 

<P>Website Address: <INPUT type="text" name="url" value="<?php echo $url;?>"> 

<P>Desired Username: <INPUT type="text" name="username" value="<?php echo $username;?>">
 
<P>Password: <INPUT type="password" name="password" value="<?php echo $password;?>"> 

<P><INPUT type="submit" value="Sign-up"> 
</FORM> 
</body>
</html>


<?php 
    exit; 
} 
?> 

</body> 
</html> 

