Anyone able to tell me why this isn’t working? I just can’t see the problem.
The code below updates the database with a new activation code.
Then an email is sent with the correct email address and the new activation code included.
The email redirects you to the activate.php page as it should. It finds no errors. And then it tells you that you have successfully registered.
What it doesn’t do:
However, it never actually updates the database so that active = 1. Active remains 0.
The activate page works properly if the original activation email is used, but the resend activation email’s link doesn’t get updated to the database as active. Here’s the code:
Recover, Update_User, and Activate functions:
[php]
function recover($mode, $email) {
$mode = sanitize($mode);
$email = sanitize($email);
$user_data = user_data(user_id_from_email($email), 'user_id', 'first_name', 'username');
if ($mode == 'username') {
email($email, 'Your username', "Hello " . $user_data['first_name'] . ",\n\nYour username is: " . $user_data['username'] . "\n\n~ The VE Team");
} else if ($mode == 'password') {
$generated_password = substr(md5(rand(999, 999999)), 0, 8);
change_password($user_data['user_id'], $generated_password);
update_user($user_data['user_id'], array('password_recover' => '1'));
email($email, 'Your password', "Hello " . $user_data['first_name'] . ",\n\nYour new password is: " . $generated_password . "\n\n~ The VE Team");
} else if ($mode == 'activation') {
$generated_activation = substr(md5(rand(999, 999999)), 0, 32);
change_activation($user_data['user_id'], $generated_activation);
email($email, 'Your new Activation Code', "Hello " . $user_data['first_name'] . ", \n\nThank you for joining the Valkyrie's Embrace Home Page. Your account is currently inactive. \n Please click or copy/paste the link below in order to activate your account.\n\nhttp://valkyries.usa.cc/activate.php?email=" . $_POST['email'] . "&email_code=" . $generated_activation . "\n\n~ The VE Team :)");
}
}
function update_user($user_id, $update_data) {
$update = array();
array_walk($update_data, 'array_sanitize');
foreach($update_data as $field=>$data) {
$update[] = '`' . $field . '` = \'' . $data . '\'';
}
mysql_query("UPDATE `users` SET " . implode(', ', $update) . " WHERE `user_id` = $user_id");
}
function activate($user_id, $email, $email_code) {
$user_id = (int)$user_id;
$email = mysql_real_escape_string($email);
$email_code = mysql_real_escape_string($email_code);
if (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0"), 0) == 1) {
mysql_query("UPDATE `users` SET `active` = 1 WHERE `email` = '$email'");
return true;
} else {
return false;
}
}
[/php]
Activate.php:
[php]
<?php include 'core/init.php'; logged_in_redirect(); include 'includes/overall/header.php'; if (isset($_GET['success']) === true && empty($_GET['success']) === true) { ?><h2> Thanks, we've activated your account... </h2>
<p> You may now log in.</p>
<?php
} else if (isset($_GET['email'], $_GET['email_code']) === true) {
$email = trim($_GET['email']);
$email_code = trim($_GET['email_code']);
if (email_exists($email) === false) {
$errors[] = 'Oops, something went wrong and we couldn\'t find that email address!';
} else if (activate($user_id, $email, $email_code) === false) {
$error[] = 'We had problems activating your account.';
}
if (empty($errors) === false) {
?>
<h2>Oops...</h2>
<?php
echo output_errors($errors);
} else {
update_user($user_data['user_id'], array('active' => '1'));
$URL="activate.php?success";
echo '<META HTTP-EQUIV="refresh" content="0;URL=' . $URL . '">';
exit();
}
} else {
$URL="index.php";
echo '<META HTTP-EQUIV="refresh" content="0;URL=' . $URL . '">';
exit();
}
include 'includes/overall/footer.php'; ?>
[/php]
Any ideas? I’m stumped. The ONLY thing it isn’t doing right is the “update_user($user_data[‘user_id’], array(‘active’ => ‘1’));” it works for the primary registration link, but not for the resend activation link. sigh