down100009 2013-11-12 16:45
浏览 26
已采纳

单击电子邮件激活链接后,php和mysql未激活新用户[关闭]

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

}
  • 写回答

1条回答 默认 最新

  • dongyang5716 2013-11-12 16:58
    关注

    Error:

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

    incorrect variable $emal_code

    Spelling errors are normally, however, before you post your code reread several times!

    It seems that you are working with PHP errors turned off, activate recommend them.

    ini_set('display_errors', '1');
    error_reporting(E_ALL);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题