This question already has an answer here:
I am trying to create a function that will check if a user is subscribed or not, but the code doesn't work, it doesn't return TRUE
even if the user is subscribed.
Here is an example of my code.
function is_subscribed($email)
{
global $DBC;
$result = mysqli_query($DBC,"SELECT * FROM users WHERE email = $email");
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_array($result)) {
if($row['subscribed'] == 'yes') {
return TRUE;
} else {
return FALSE;
}
}
}
}
$user_email = $_SESSION['email'];
if(is_subscribed($user_email)) {
echo "YES!";
}
</div>
You need to wrap $email into quotes because it is a string. So:
SELECT * FROM users WHERE email = '$email'
just do few change add sigle quote
$result = mysqli_query($DBC,"SELECT * FROM users WHERE email = '$email'");