Try to return JSON data generated with SQL statement from PHP script to JS webpage but get null instead
I want to return **JSON** data from a resulted SQL statement in a PHP script upon pressing **Submit** button, but I receive `null` instead.

*I'll be using the returned JSON to filter-show markers on my Google Map, but for now I just want to get the data back across to my jQuery page from PHP script so I can manipulate/use it.*


**Submit button**:

*HTML*

    <input type="submit" id="filter" value="Filter" />

*JS*

    $('#myform').on('submit', function(e) {
    					e.preventDefault();
    					var myData = $('#myform').serializeArray();
    					$.getJSON('myscript.php', myData, function(json){
    						alert(json);// actually filter for later					
    					});	
    				});

**PHP script**:

    // action is a hidden form control I use to check if form was submitted
        if(isset($_POST["action"])){
        
        	if(isset($_POST["color"]) && isset($_POST["zipcode"])){
        		// try to open a connection to a MySQL server
        		$connection = mysql_connect($host, $username, $password) or die("Could not connect" . mysql_error());
        		// select the active MySQL database to work with
        		$db_selected = mysql_select_db($database, $connection) or die("Can\'t use db:" . mysql_error());
        		
        		$query = 'sql statement to return resutls based on what color and zipcode was provided';
        		$result = mysql_query($query) or die("Can\'t do that: " . mysql_error());
        	}
        	
        	//	close connection to the database
        
        
        echo json_encode($result);
        mysql_close($connection);
        }
Try to return JSON data generated with SQL statement from PHP script to JS webpage but get null instead
===

I want to return **JSON** data from a resulted SQL statement in a PHP script upon pressing **Submit** button, but I receive `null` instead.

*I'll be using the returned JSON to filter-show markers on my Google Map, but for now I just want to get the data back across to my jQuery page from PHP script so I can manipulate/use it.*


**Submit button**:

*HTML*

    <input type="submit" id="filter" value="Filter" />

*JS*

    $('#myform').on('submit', function(e) {
    					e.preventDefault();
    					var myData = $('#myform').serializeArray();
    					$.getJSON('myscript.php', myData, function(json){
    						alert(json);// actually filter for later					
    					});	
    				});

**PHP script**:

    // action is a hidden form control I use to check if form was submitted
        if(isset($_POST["action"])){
        
        	if(isset($_POST["color"]) && isset($_POST["zipcode"])){
        		// try to open a connection to a MySQL server
        		$connection = mysql_connect($host, $username, $password) or die("Could not connect" . mysql_error());
        		// select the active MySQL database to work with
        		$db_selected = mysql_select_db($database, $connection) or die("Can\'t use db:" . mysql_error());
        		
        		$query = 'sql statement to return resutls based on what color and zipcode was provided';
        		$result = mysql_query($query) or die("Can\'t do that: " . mysql_error());
        	}
        	
        	//	close connection to the database
        
        
        echo json_encode($result);
        mysql_close($connection);
        }