PHP 和 MySQL 在单击电子邮件激活链接后未激活新用户


php and mysql not activating new user after clicking email activation link

我正在用PHP创建一个注册/登录系统。 我的代码能够通过电子邮件向新用户发送激活链接,但Wen用户单击链接,用户未激活。请任何人都可以帮忙,代码如下...

用户.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'] . ",'n'nYou need to activate your account by clicking the link below:'n'nhttp://fredhosting.com/real/activate.php?email=" . $register_data['email'] . "&email_code=" . $register_data['email_code'] . "'n'n - Fredhosting.com");
}

激活.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(); 
    }
}

错误:

if (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM 
`user` WHERE `email` = '$email' 
AND `email_code` = '$emal_code' 
AND `active` = 0"), 0) == 1)

不正确的变量 $emal_code

但是,拼写错误通常是在您发布代码之前重读几次!

似乎您正在关闭PHP错误,请激活推荐它们。

ini_set('display_errors', '1');
error_reporting(E_ALL);