I have the following code and the fetch_assoc is not working, when i manually put in the email address and hash it will post active='1' fine see code below any help would be appreciated.
<?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!';
}
Change your code as below, it will work
<?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!';
}
?>