I'm still having problems with my validation page. I followed the example given in PHP Main for making a member system (except I added and changed some things). Anyways .... here is my registration code: (You'll also notice that I have absolutely no security)
<?php
require("connect.php");
$firstName=$_POST['firstName'];
$middleIn=$_POST['middle'];
$lastName=$_POST['lastName'];
$userAddress=$_POST['address'];
$userState=$_POST['state'];
$userZIP=$_POST['zip'];
$userCountry=$_POST['country'];
$year=$_POST['theyear'];
$month=$_POST['month'];
$day=$_POST['day'];
$username=$_POST['username'];
$password=$_POST['password'];
$password2=$_POST['confirmPass'];
$email=$_POST['email'];
$validate_key=md5(time()+rand(1000,9999).$username);
$message="Thank you for singing up at Tears Fall. Your user info is below:\n\n
Username: $username\n
Password: $password\n\n
Before you can log into your account, you must activate your account. Go to the url below to activate your
account:\n\n
http://tearsfall.pcriot.com/validate.php?validate_key=$validate_key\n\n
Please don't reply to this email, it's automated.";
if(empty($firstName)||empty($lastName)||empty($username)||empty($password)||empty($password2)||empty($email)) {
die('One or more fields are missing. Please return to the <a href="./registration.php">Registration</a> page.');
}
if($password!=$password2) {
die('Passwords do not match.');
}
$password=sha1($password);
if($userZIP!="") {
if(strlen($userZIP)<5) {
die('Please make sure your ZIP code is at least 5 digits long.');
}
}
if($userState!="" && $userCountry=="") {
$usercountry="USA";
}
if($month=="January"){
$month=1;
}
elseif($month=="February") {
$month=2;
}
elseif($month=="March") {
$month=3;
}
elseif($month=="April") {
$month=4;
}
elseif($month=="May") {
$month=5;
}
elseif($month=="June") {
$month=6;
}
elseif($month=="July") {
$month=7;
}
elseif($month=="August") {
$month=8;
}
elseif($month=="September") {
$month=9;
}
elseif($month=="October") {
$month=10;
}
elseif($month=="November") {
$month=11;
}
elseif($month=="December") {
$month=12;
}
$theDate = mktime(0,0,0,$month,$day,$year);
$userbirthDate = date("Y-m-d", $theDate);
$result = mysql_query("SELECT * FROM users WHERE username='$username';");
if(mysql_num_rows($result)==1) {
die("The username $username is already in use.");
}
$result = mysql_query("SELECT * FROM users WHERE email='$email';");
if (mysql_num_rows($result)==1) {
die("The e-mail address $email is already in use.");
}
mysql_query("INSERT INTO users(firstName,middleIn,lastName,userAddress,userState,userZIP,userCountry,userbirthDate,username,password,validcode,email,usergroup) VALUES('$firstName','$middleIn','$lastName','$userAddress','$userState','$userZIP','$userCountry','$userbirthDate','$username','$password','$validate_key','$email', 1);") or die(mysql_error());
mysql_close();
mail($email,"Validate Your Account",$message);
echo "Thank you for registering. You'll receive an e-mail shortly with instructions to validate your account. You will be redirected to the main page in 15 seconds.";
?>
And here is my validation code:
<?php
require("connect.php");
$validate_key=$_GET['validate_key'];
$result = mysql_query("SELECT * FROM users WHERE validcode='$validate_key' AND usergroup!=1");
if (mysql_num_rows($result)==1) {
die('You have already validated your account!');
}
mysql_query("UPDATE users SET usergroup=2 WHERE validcode='$validate_key'");
mysql_close();
echo 'Your account has been validated successfully. You may log into it now. In 15 seconds you will be redirected to the main page.';
?>
Where have I went wrong? *Dies*