Jo
2010-03-24 15:25:47 UTC
heres the code again
include('connectionfile.php');
$test_username = $_POST='username';
$test_password = $_POST='password';
if(!eregi("[^A-Za-z0-9]", $test_username) && !eregi("[^A-Za-z0-9]", $test_password))
{
$name_collision = "SELECT * FROM users WHERE username = '$_POST[username]'";
$email_collision = "SELECT * FROM users WHERE email = '$_POST[email]'";
//name result will do the action name collision which is select all
//from users where the username is equal to the person's typed username.
$name_result = mysql_query($name_collision);
$email_result = mysql_query($email_collision);
//name rows will get the number of rows in name result. it will check
//if there is any rows with the name collision data.
$name_rows = mysql_num_rows($name_result);
$email_rows = mysql_num_rows($email_result);
//checks if email and username isn't in the database
if($name_rows == 0 && $email_rows == 0)
{
//if the post variable pass is exactly equal to the confirm pass
//if the email is exactly equal to the email field.
if($_POST['password'] == $_POST['password2'] && $_POST['email'] == $_POST['email2'])
{
$confirmation_code = md5(uniqid(rand()));
//strip out all the tags so that hackers can't hack
$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);
$email = strip_tags($_POST['email']);
// insert into the temp and set the field code into a random unique letters and make
//username = to the username and the email.
$sql = "INSERT INTO temp SET code = '$confirmation_code', username='$name', password = '$password', email = '$email'";
$insert_result = mysql_query($sql);
if($insert_result)
{
//send a message to the users email entered.
// dot after the message means add-on to the message string
$message = "Your confirmation link \r\n";
$message.= "Click on this link to activate your account: \r\n";
$message.= "localhost/Confirmation.php?passkey='$confirmation_code'";
$sent_mail = mail("$email","Registration Confirmation","$message", "From: Pasantorxstudios@live.co.uk");
if($sent_mail)
{
echo 'A confirmation email has been sent to your email address.';
}
else
{
die('Confirmation email not sent');
}
}
else
{
die('Account not added to the database!');
}
}
else
{
die("Email and or password confirms doesn't match");
}
}
// if it is it will die and print out on the screen.
else
{
die('Email or username is allready in use!: ' . mysql_error());
}
}
else
{
die('Username and password can only contain letters and password, try again.' . mysql_error());
}
?>