AJAX result always returns false / false

Hello
I’m having some troubles with my code. My current code couse that I’m doing should give me alert which depends on infromation from server - if email was written to subscribe list or not. And it almost works - the only problem is that I’m getting only false alert, even if the emal has been written.
Below is some code

Here is JS script:

 $("button.submit").click(function() {
        $.ajax({
            type: "POST", 
            url: "email.php", 
            data: { email: $(".email").val() }, 
            success: function(result) { console.log(result)
                alert(result ? "Email has been added to our subscribe list!" : "Email already exist in our subscribe list!");
            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.error(errorThrown);
            }
        }) 

And there is PHP file :

    $email = filter_input(INPUT_POST, 'email');
    if (!empty($email)){
        $host = "localhost";
        $dbusername ="root";
        $dbpassword ="";
        $dbname = "email";

        $conn = new mysqli ($host,$dbusername, $dbpassword , $dbname);
        if (mysqli_connect_error()){
            die('Connection problem('.mysqli_connect_errno().')'.mysqli_connect_error()); 
        }
        else{
            $sql = "INSERT INTO `email` (`email_id`, `email`) VALUES (NULL, '$email');";
            if ($conn->query($sql)){
                $return = true;
            }
            else{
                $return = false;
            }
            $conn->close();   
    }}
?>

Do you have any ideas what did I do wrong ? My JS level is kinda low ( I’m still new to JS )
I’d be grateful for your advices

There are so many things that could be wrong here.

First off., ensure your DB password is right. Goto command line and type

mysql -uroot -p
You be prompted for a password and ensure it is actually connecting.

If it’s not you’ll need to start mysql. Depending on your distro of linux it could be
systemctl start mysqld

Next after you connect., you need to ensure $email on the server side is even a value.
You could do var_dump($email) after your filter statement. If there’s no value,. then it’s either your ajax is not sending the field over or it’s an invalid email syntax.

The way you’re inserting into your database is inviting SQL injection., so I highly recommend reading up on PDO.

BTW,. to see the value of your var_dump from server., you’ll need to open up your developer tools and click network tab. From there click the line that has 'xhr' listed on it and click 'preview