检查电子邮件是否已激活不起作用

时间:2015-11-29 20:59:02

标签: php mysql session

我刚创建了一个脚本,用于检查用户是否已激活其帐户。如果是这样,它应该说“该帐户已被激活”,如果没有,则激活该帐户。问题是它总是说“激活是成功的”。有人能帮帮我吗?

<?php
session_start();
include_once 'dbconnect.php';
$dbconnect = mysqli_connect('server', 'user', 'password', 'database');

if (isset($_GET['email'])) {
    $email = $_GET['email'];
}
if (isset($_GET['status']) && (strlen($_GET['status']) == 32)) {
    $status = $_GET['status'];
}

if (isset($email) && isset($status)) {

    $sql = "SELECT status FROM users WHERE email='$email'";
    $result = mysql_query($sql);

    if ($result == 'active') {

        echo" <div style='position:absolute;left:29.5%;top:10%;width:41%;' class='alert alert-danger'>
             <a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>
             <strong>Chyba!</strong> &#218;&#269;et je ji&#158; aktivov&#225;n!
             </div>";
    } else {

        $query_activate_account = "UPDATE users SET status='active' WHERE(email ='$email' AND status='$status')";
        $result_activate_account = mysqli_query($dbconnect, $query_activate_account);

        echo" <div style='position:absolute;left:29.5%;top:10%;width:41%;' class='alert alert-success'>
             <a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>
             <strong>Úspěch!</strong> Aktivace proběhla úspěšně! <a href='signin.php'>Přihlášení</a>
             </div>";
    }
}
?>

1 个答案:

答案 0 :(得分:-1)

更新

 $sql = "SELECT status FROM users WHERE email='$email'";
    $result = mysql_query($sql);
to 
 $sql = "SELECT status FROM users WHERE email='$email'";
    $result = mysql_query($sql);
while($row = mysql_fetch_assoc($result )){
  $status = $row['status'];
}

并替换

if ($result == 'active') {

if ($status== 'active') {