JavaScript POST to PHP - why does it return null without an If? : <p>This one has really been melting my brain because I'm just not sure why the PHP returns a null set to the front end when it's formatted like this:</p>

<pre><code>&lt;?php
require_once 'tempdbconfig.php';

$email=$_POST['email'];

try {
//if($email = "t*****@gmail.com"){
    $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);

    $sql="SELECT users_id FROM photow_users WHERE email_address = '$email'";

    $result = $conn-&gt;prepare($sql);

    $result-&gt;execute();

    $data = $result-&gt;fetchAll();

    $catValues = array();

    foreach($data as $row) {
        $users_id=$row['users_id'];

        $category_sql="SELECT * FROM photow_categories WHERE users_id = '$users_id'";

        $category_result = $conn-&gt;prepare($category_sql);

        $category_result-&gt;execute();

        $category_data = $category_result-&gt;fetchAll();

        $catValues = array();

        $i = 0;

        foreach($category_data as $category_row) {
            $categories = array();

            $categoryid = $category_row['category_id'];
            $category = $category_row['name'];

            $categories["ID"] = $categoryid;
            $categories["Category"] = $category;

            $catValues[$i]=$categories;
            $i++;       
        }
    }

    echo json_encode($catValues);
//}
//else
//{
//  echo 'no categories';
//}

} catch (PDOException $pe) {
    die("Could not connect to the database $dbname :" . $pe-&gt;getMessage());
}

?&gt;
</code></pre>

<p>But if I uncomment the if else (the condition is the email that my currently logged in account on the front end is using, so it's akin to me asking if the sky is blue) I get the properly formatted JSON returned to the front end. Am I missing something about PHP or have I made a horrible mistake somewhere?</p>

<p>This is the ajax call in case it's something there that's effecting it - localstorage does contain the correct email address by the way.</p>

<pre><code>var email=localStorage.email;

$.ajax({
        type: "POST",
        url: "http://w****.azurewebsites.net/getCategoriesjson.php",
        data: 'email='+email,
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function(data){
            var html = '';
            $.each(data, function(index,value){
                html+= '&lt;option value="'+value['ID']+'"&gt;'+value['Category']+'&lt;/option&gt;';
            }); 
            $('#categories').html(html);
        }
    });
</code></pre>
