-2

我正在用 php 创建一个注册/登录系统。我的代码能够通过电子邮件向新用户发送激活链接,但是当用户点击链接时,用户未激活..请任何人帮助,代码如下...

用户.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(); 
    }

}
4

1 回答 1

1

错误:

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);
于 2013-11-12T16:58:13.340 回答