Q:

Unable to pass value to php POST via javascript

I am trying to update the text from textbox to database using the onclick event and calling a javascript function.  
This is the javascript code
function send_post() 
{

    var hr = new XMLHttpRequest();
    var url ="send_post.php";
    var fn = document.getElementById("post").value;

    var vars = "post="+fn;
    hr.open("POST",url,true);

    hr.setRequestHeader("Content-type","application/x-www-form-urlencode");
    hr.onreadystatechange = function() {
        if (hr.readyState == 4 && hr.status ==200) {
            var return_data = hr.responseText;
            document.getElementById("status").innerHTML = return_data;

        }
    }
    hr.send(vars);
    document.getElementById("status").innerHTML = fn;

}

This is the php file code 
<? php include 'inc/connect.inc.php'; 

$post =@$_POST['post'];
if ($post ! = "") {
    $date_added = date("Y-m-d");
    $added_by = "test123";
    $user_posted_to = "test123";

    $sqlCommand = "INSERT INTO posts VALUES('','$post','$date_added','$added_by','$user_posted_to')";
    $query = mysql_query($sqlCommand) or die (mysql_error());
}
else{
    echo "Write something to post."; 

}

? >

But I get this error from the php :
Undefined index: post  on line 3

A:

The MIME type you are trying to use is application/x-www-form-urlencoded (with a d on the end). 
PHP doesn't know how to parse data encoded as application/x-www-form-urlencode (without the d) so it doesn't populate $_POST for your code.