MySQL查询没有更新,但PHP没有显示错误

时间:2013-01-12 07:48:12

标签: php login registration

这是供用户激活的。

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 `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;
    }
}

Activation.php

if (isset($_GET['success']) === true && empty($_GET['success'])===true){
    echo 'Account activated!';
}
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!';
    }else if (activate($email, $email_code === false)){
        $errors[] = 'We have problems activating your account!';
    }
    if (empty($errors) === false){
        echo output_errors($errors);
    }else{
        header('Location:activate.php?success');
        exit();
    }
}else{
    header('Location:go.php');
    exit();
}

它说'帐户已激活!'正如我回应,但它没有改变表中的字段。它根本没有激活。这有什么问题?

1 个答案:

答案 0 :(得分:0)

您必须更改此功能

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 `users` WHERE `email` = '$email' AND `email_code` = '$email_code' AND `active` = 0"), 0) == 1){
    if(mysql_query("UPDATE `users` SET `active` = 1 WHERE `email` = '$email'")){
        return true;
        }
  else{
    return false;
    }
  }
}