<?php
session_start();
include ("includes/connect.php");
include ("html_codes.php");
if (isset ($_POST ['submit'])) {
$error = array ();
if (empty ($_POST ['username'])) {
$error [] = 'please enter a username.';
}
else if (ctype_alnum($_POST['username'])) {
$username = $_POST ['username'];
}else{
$error[]= 'username must consist of letters and numbers only';
}
if (empty ($_POST ['email'])) {
$error [] = 'please enter your email.';
}
else if (preg_match ("/^ ([a-zA-Z0]) +([a-zA-Z0-9_-])+([a-zA-Z0-\._-]+)+$/", $_POST ['email'])){
$email= mysql_real_escape_string($_POST ['email']);
$error[]='your e-mail adress is invalid';
}
if (empty ($_POST ['password'])) {
$error[]='please enter your password';
}
else{ $password= mysql_real_escape_string($_POST ['password']);
}
if (empty ($error)){
$result =mysql_query ("SELECT * FROM users WHERE email = '$email' OR username = '$username'")
or die (mysql_error());
if (mysql_num_rows ($result)==0){
$activation = md5 (uniqid (rand(), true));
$result2 =mysql_query ("INSERT INTO tempusers (user_id,username,email,password,activation) VALUES ('', '$username', '$email', 'password', '$activation')")
or die (mysql_error());
}
if (!result2) {
die ( 'could not insert into database:' .mysql_error());
}
else{
$message="To activate your account, please click on this link:\n\n";
$message="http://lisa1986.com". '/activae.php?email= '.urlencode ($email). "&key= $activation";
mail($email, 'Registration Confirmation', $message);
header ('Location: prompt.php?x=1');
}
}
else {
header ('Location: prompt.php?x=2');
}
$error_message = '<span class = "error">';
foreach ($error as $key=> $values){
$error_message='</span><br/><br/>';
}
}
?>