0

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!";
}
chris85
  • 23,846
  • 7
  • 34
  • 51
tr0in
  • 67
  • 1
  • 6

2 Answers2

0

You need to wrap $email into quotes because it is a string. So:

SELECT * FROM users WHERE email = '$email'
Yolo
  • 1,569
  • 1
  • 11
  • 16
0

just do few change add sigle quote

$result = mysqli_query($DBC,"SELECT * FROM users WHERE email = '$email'");
Abanoub Makram
  • 463
  • 2
  • 13