mysqli fetch_assoc() not posting



我有以下代码,fetch_assoc不起作用,当我手动输入电子邮件地址和哈希时,它将发布 active='1' 很好,请参阅下面的代码,任何帮助将不胜感激。

<?php
session_start();
require_once("db.php");
$hash = mysqli_real_escape_string($comm, $_POST["token"]);
$email = mysqli_real_escape_string($comm, $_POST["email"]);
$sql = "SELECT * FROM users WHERE email='$email' AND hash='$hash'";
$result = $conn->query($sql);
if ($result->num_rows == 0) {
$row = $result->fetch_assoc();
if ($row['active'] == '1') {
echo 'You Have Already Activated Your Account';
} else {
$sql1 = "UPDATE users SET active='1' WHERE email='$email' AND hash='$hash'";
// If i use the email address and the hash then it works
// $sql1 = "UPDATE users SET active='1' WHERE email='email@mydomain.com' AND hash='28a78fea4088711fc7a2bb1a6abeb3aa'";
if ($conn->query($sql1)) {
$SESSION['userActivated'] = true;
header("Location: login.php");
exit();
}
}
} else {
echo 'Token Mismatch!';
}

按如下方式更改代码,它将起作用

<?php
session_start();
require_once("db.php");
$hash = mysqli_real_escape_string($comm, $_POST["token"]);
$email = mysqli_real_escape_string($comm, $_POST["email"]);
$sql = "SELECT * FROM users WHERE email='$email' AND hash='$hash'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
if ($row['active'] == '1') {
echo 'You Have Already Activated Your Account';
} else {
$sql1 = "UPDATE users SET active='1' WHERE email='$email' AND hash='$hash'";
// If i use the email address and the hash then it works
// $sql1 = "UPDATE users SET active='1' WHERE email='email@mydomain.com' AND hash='28a78fea4088711fc7a2bb1a6abeb3aa'";
if ($conn->query($sql1)) {
$SESSION['userActivated'] = true;
header("Location: login.php");
exit();
}
}
} else {
echo 'Token Mismatch!';
}

?>

最新更新