help with activation key for email verification script
Posted: Mon Mar 29, 2010 11:52 pm
Hello, I need help with this script. I am trying to have an activation key generated and emailed to the person registering on my site. Everything seems to work except the activation key itself (I don't get any errors), it seems that it is not being generated. I've verified connection to the database and every other field in that table populated with no issues prior to adding this script. Thanks in advance for any assistance.
Code: Select all
<?php
mysql_connect("localhost", loginname, "mypassword") or die(mysql_error());
mysql_select_db("crashhorizon") or die(mysql_error());
if ($_POST['form_submitted'] == '1') {
$activationKey = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand();
$sql="INSERT INTO user_auth (user, password, email, activationkey, status)
VALUES
('$_POST[user]', '$_POST[password]', '$_POST[email]','$activationKey', 'verify')";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
} else {
}
echo "An email has been sent to $_POST[email] with an activation key. Please check your mail to complete registration.";
##Send activation Email
$to = $_POST[email];
$subject = " horizonitsolutions.com Registration";
$message = "Welcome to our website!\r\r You, or someone using your email address, has completed registration at horizonitsolutions.com. You can complete registration by clicking the following link: \rhttp://www.horizonitsolutions.com/register/verify.php?$activationKey\r\r If this is an error, ignore this email and you will be removed from our mailing list.\r\r
Regards, horizonitsolutions.com Team";
$headers = 'From: noreply@ horizonitsolutions.com' . "\r\n" .
'Reply-To: noreply@ horizonitsolutions.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
##User isn't registering, check verify code and change activation code to null, status to activated on success
$queryString = $_SERVER['QUERY_STRING'];
$query = "SELECT * FROM user_auth";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
if ($queryString == $row["activationkey"]){
echo "Congratulations!" . $row["user"] . " is now a member of horizonitsolutions.com";
$sql="UPDATE user_auth SET activationkey = '', status='activated' WHERE (id = $row[id])";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
}
}