我刚创建了一个脚本,用于检查用户是否已激活其帐户。如果是这样,它应该说“该帐户已被激活”,如果没有,则激活该帐户。问题是它总是说“激活是成功的”。有人能帮帮我吗?
<?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'>×</a>
<strong>Chyba!</strong> Účet je již aktivová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'>×</a>
<strong>ĂšspÄ›ch!</strong> Aktivace probÄ›hla ĂşspěšnÄ›! <a href='signin.php'>PĹ™ihlášenĂ</a>
</div>";
}
}
?>
答案 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') {