i am creating a registration/login system with php. my code is able to send an activation link to the new user via email, but wen user clicks on the link, user is not activated..pls can anyone help, the codes are below...
users.php
function activate($email, $email_code) {
$email = mysql_real_escape_string($email);
$email_code = mysql_real_escape_string($email_code);
if (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `user` WHERE `email` = '$email' AND `email_code` = '$emal_code' AND `active` = 0"), 0) == 1) {
if (mysql_query("UPDATE `user` SET `active` = 1 WHERE `email` = '$email'")){
return true;
} else {
return false;
}
}
}
function register_user ($register_data) {
array_walk($register_data, 'array_sanitize');
$register_data['password'] = md5($register_data['password']);
$fields = '`' . implode('`, `', array_keys ($register_data)) . '`';
$data = '\'' . implode('\', \'', $register_data) . '\'';
mysql_query("INSERT INTO `user` ($fields) VALUES ($data)");
email($register_data['email'], 'Activate your account', "Hello " . $register_data['username'] . ",
You need to activate your account by clicking the link below:
http://fredhosting.com/real/activate.php?email=" . $register_data['email'] . "&email_code=" . $register_data['email_code'] . "
- Fredhosting.com");
}
Activate.php
if (isset($_GET['success']) === true && empty($_GET['success']) === true) {
?>
<h2>Thanks, we have activated your account...</h2>
<p>You can 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 could not find that email address.';
} else if (activate($email, $email_code) === false) {
$errors[] = 'We had some issues activating your account.';
}
if (empty($errors) === false) {
?>
<h2>Oops...</h2>
<?php
echo output_errors($errors);
} else {
header('Location: activate.php?success');
exit();
}
}