Not receiving $_POST[] parameter
<p>I am trying to send a value from my test.php to my backgroundScript.php through the $_POST method and when print out the value that is being sent i get the correct value but when i go to my backgroundScript file to see if the value was sent - nothing gets printed out, it equals null --------------------------------test.php file - main code</p>

<pre><code>try {  
  # MySQL with PDO_MYSQL  
  $DBH = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);  
  $DBH-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

  //$DBH-&gt;prepare('SELECT first FROM contacts');
}  
catch(PDOException $e) { 
    echo "I'm sorry, I'm afraid I can't do that.";  
    file_put_contents('PDOErrors.txt', $e-&gt;getMessage(), FILE_APPEND);   
}  
//get query
$FNresult=$DBH-&gt;query('SELECT first FROM contacts'); 
//set fetch mode
$FNresult-&gt;setFetchMode(PDO::FETCH_ASSOC);

$dropdown = "&lt;select name='contacts' id='contacts' &gt;";

while($row =$FNresult-&gt;fetch()) {

  $dropdown .= "\r\n&lt;option  value='{$row['first']}'&gt;{$row['first']}&lt;/option&gt;";
 // echo getLN();

}

$dropdown .= "\r\n&lt;/select&gt;";

echo $dropdown;


//}
/*
//                  Get last name

function getLN(){
    $query = "SELECT last FROM contacts";
    $LNresult=mysql_query($query);

    $last;
    while($row = mysql_fetch_assoc($LNresult)) {

        $last = "{$row['last']}";

    }
    echo $last;
}//end getLN
*/

$DBH = null; 
?&gt;


&lt;script type="text/javascript"
     src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt;   
&lt;!-- javascript on client-side --&gt;
&lt;script type="text/javascript"&gt;  

var dropdown = $('#contacts');

document.write(dropdown.val());

dropdown.bind('change', function(){

    $.post('backgroundScript.php', 
        { 
            first: dropdown.val()

        },
        function(response) {
            $('#first').val(response.first);
            $('#last').val(response.last);
            $('#phone').val(response.phone);
            // Repeat for all of your form fields
        },
        'json'
    );

});

&lt;/script&gt;

&lt;form action="insert.php" method="post"&gt;
First Name: &lt;input type="text" id="first"  &gt;&lt;br&gt;
Last Name: &lt;input type="text" id="last"&gt;&lt;br&gt;
Phone: &lt;input type="text" id="phone"&gt;&lt;br&gt;
Mobile: &lt;input type="text" id="mobile"&gt;&lt;br&gt;
Fax: &lt;input type="text" id="fax"&gt;&lt;br&gt;
E-mail: &lt;input type="text" id="email"&gt;&lt;br&gt;
Web: &lt;input type="text" id="web"&gt;&lt;br&gt;
&lt;input type="Submit"&gt;
&lt;/form&gt;
</code></pre>

<p>backgroundScript.php ------------------------------------------- where value is sent</p>

<pre><code>try {  
  # MySQL with PDO_MYSQL  
  $DBH = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);  
  $DBH-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

  //$DBH-&gt;prepare('SELECT first FROM contacts');
}  
catch(PDOException $e) { 
    echo "I'm sorry, I'm afraid I can't do that.";  
    file_put_contents('PDOErrors.txt', $e-&gt;getMessage(), FILE_APPEND);   
}  

$first= $_POST['first'];
print_r("print value: $first");
//$first = "david";
$sth = $DBH-&gt;prepare('SELECT *
    FROM contacts
    WHERE first = :first');
$sth-&gt;bindParam(':first', $first, PDO::PARAM_STR);
$sth-&gt;execute();

$row = $sth-&gt;fetch();


$returnArray = array( 
'first' =&gt; $row["first"],
'last' =&gt; $row["last"], 
'phone' =&gt; $row["phone"], 
);
//print_r("After pureeing fruit, the colour is: $returnArray");
/*echo "&lt;pre&gt;";
print_r($returnArray);
echo "&lt;/pre&gt;";
exit;*/


// background script

// retrieve data based on $_POST variable, set to $returnArray
/*while($row = $sth-&gt;fetch(PDO::FETCH_ASSOC)){
  // do something with row

}
$returnArray = array( 
'first' =&gt; $row["first"], 
);


echo "&lt;pre&gt;";
print_r($returnArray);
echo "&lt;/pre&gt;";
exit;
*/



/****************************
 * the structure of returnArray should look something like
     array(
         'first' =&gt; firstName,
         'last' =&gt; lastName,

     )*/
    // echo json_encode(array('first' =&gt; "hello", 'last' =&gt; "Other value"));
//echo json_encode($returnArray);
$DBH = null; 
</code></pre>

############################ UPDATE TO TEST.PHP

<pre><code>try {  
  # MySQL with PDO_MYSQL  
  $DBH = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);  
  $DBH-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

  //$DBH-&gt;prepare('SELECT first FROM contacts');
}  
catch(PDOException $e) { 
    echo "I'm sorry, I'm afraid I can't do that.";  
    file_put_contents('PDOErrors.txt', $e-&gt;getMessage(), FILE_APPEND);   
}  
//get query
$FNresult=$DBH-&gt;query('SELECT first FROM contacts'); 
//set fetch mode
$FNresult-&gt;setFetchMode(PDO::FETCH_ASSOC);


//}
/*
//                  Get last name

function getLN(){
    $query = "SELECT last FROM contacts";
    $LNresult=mysql_query($query);

    $last;
    while($row = mysql_fetch_assoc($LNresult)) {

        $last = "{$row['last']}";

    }
    echo $last;
}//end getLN
*/

$DBH = null; 
?&gt;


&lt;script type="text/javascript"
     src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt;   
&lt;!-- javascript on client-side --&gt;
&lt;script type="text/javascript"&gt;  

var dropdown = $('#contacts');

document.write(dropdown.val());

dropdown.bind('change', function(){

    $.post('backgroundScript.php', 
        { 
            first: dropdown.val()

        },
        function(response) {
            $('#first').val(response.first);
            $('#last').val(response.last);
            $('#phone').val(response.phone);
            // Repeat for all of your form fields
        },
        'json'
    );

});

&lt;/script&gt;

&lt;form action="insert.php" method="post"&gt;
&lt;?php

$dropdown = "&lt;select name='contacts' id='contacts' &gt;";

while($row =$FNresult-&gt;fetch()) {

  $dropdown .= "\r\n&lt;option  value='{$row['first']}'&gt;{$row['first']}&lt;/option&gt;";
 // echo getLN();

}

$dropdown .= "\r\n&lt;/select&gt;";



echo $dropdown;
?&gt;

First Name: &lt;input type="text" name="first" id="first" &gt;&lt;br&gt;
Last Name: &lt;input type="text" id="last"&gt;&lt;br&gt;
Phone: &lt;input type="text" id="phone"&gt;&lt;br&gt;
Mobile: &lt;input type="text" id="mobile"&gt;&lt;br&gt;
Fax: &lt;input type="text" id="fax"&gt;&lt;br&gt;
E-mail: &lt;input type="text" id="email"&gt;&lt;br&gt;
Web: &lt;input type="text" id="web"&gt;&lt;br&gt;
&lt;input type="Submit"&gt;
&lt;/form&gt;
</code></pre>

<p>Now i get a undefined  in javascript when i try to print out value of dropdown</p>

######################################## UPDATE

<pre><code>&lt;form action="backgroundScript.php" method="post"&gt;

&lt;script type="text/javascript"
     src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt;   
&lt;!-- javascript on client-side --&gt;
&lt;script type="text/javascript"&gt;  

var dropdown = $('#contacts');

document.write(dropdown.val());

dropdown.bind('change', function(){

    $.post('backgroundScript.php', 
        { 
            first: dropdown.val()

        },
        function(response) {
            $('#first').val(response.first);
            $('#last').val(response.last);
            $('#phone').val(response.phone);
            // Repeat for all of your form fields
        },
        'json'
    );

});

&lt;/script&gt;


&lt;?php

$dropdown = "&lt;select name='contacts' id='contacts' &gt;";

while($row =$FNresult-&gt;fetch()) {

  $dropdown .= "\r\n&lt;option  value='{$row['first']}'&gt;{$row['first']}&lt;/option&gt;";
}
$dropdown .= "\r\n&lt;/select&gt;";

echo $dropdown;
?&gt;

First Name: &lt;input type="text" name="first" id="first" &gt;&lt;br&gt;
Last Name: &lt;input type="text" name="last" id="last"&gt;&lt;br&gt;
Phone: &lt;input type="text"  name="phone" id="phone"&gt;&lt;br&gt;
Mobile: &lt;input type="text" id="mobile"&gt;&lt;br&gt;
Fax: &lt;input type="text" id="fax"&gt;&lt;br&gt;
E-mail: &lt;input type="text" id="email"&gt;&lt;br&gt;
Web: &lt;input type="text" id="web"&gt;&lt;br&gt;
&lt;input type="Submit"&gt;
&lt;/form&gt;
</code></pre>
