dataString is :
{"feedback_type":"000","error_type":"","textarea":"blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah"}
I used the following code to post to the PHP:
// ajax post
$.ajax({
type: "POST",
url: "core/poster.php" ,
data: dataString,
success:function()
{
alert("Success!");
}
});
return false;
And php file:
<?php
require 'Class_DBOperation.php';
require 'global.php';
// Establish Database Connection
$dbOperation = new class_DBOperation(DBHOST,DBUSER,DBPWD,DBNAME,DBCHARSET);
// Receive dataString
$content=$_POST['feedback_type'];
$run=mysql_query("insert into reports values (NULL, '".$content."')");
?>
The problem is why $content is empty? What should I do ? any ideas?
This isnt a direct solution, but it may help you find out what is wrong. Try dumping out the contents of your $_POST superglobal, this will inform you of how the data was received. Try something like:
print '<pre>';
print_r ($_POST);
print '<pre>';
Add a response in your success function and alert it
$.ajax({
type: "POST",
url: "core/poster.php" ,
data: dataString,
success:function(response)
{
alert(response);
}
});
And in your poster.php file try adding the following to the top within the PHP tag.
ini_set("display_errors", 1);
var_dump($_POST);
This should give you a place to start and debug what's going on.
Remove your double quotes for parameter names
{
feedback_type: "000",
error_type: "",
textarea: "blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah"
}
You're sending a JSON string as the parameter string.
Parameters should be formatted as follows:
foo=bar,foo2=bar2,foo3=bar3
etc...
You could either reformat the string to follow the norm:
JS:
var dataString = "feedback_type=000&error_type=&textarea=blahblahblah";
PHP:
echo $_POST['feedback_type']; // 000
echo $_POST['error_type']; // null
echo $_POST['textarea']; // blahblahblah
or you could pass the JSON string as a POST parameter:
JS:
var jsonObject = {
"feedback_type" : "000",
"error_type" : "",
"textarea" : "blahblah"
}
var jsonString = '{"feedback_type":"000","error_type":"","textarea":"blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah"}';
// OR
var jsonString = JSON.stringify(jsonObject);
var dataString = "json_string=" + jsonString;
PHP:
// String - suitable for database input
echo $_POST['json_string']; // String: {"feedback_type":"000","error_type":"","textarea":"blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah"}
// Parse into array
$json_array = json_decode($_POST['json_string']);