Take the 2-minute tour ×

I'm using this jquery to serialize my form and pass it to a PHP script called write.php;


    var_form_data = $(this).serialize();

       type: "POST",
       url: "write.php",
       data: var_form_data,
       success: function(msg){
         alert( "Data Saved: " + msg );


Normally, lets say I had a form with the fields Address F_name and S_name, I'd do something like this to get the values into PHP vars;

$Address = $_POST["Address"];
$F_name = $_POST["F_name"];
$S_name = $_POST["S_name"];

I'd then go onto persist these to the DB

However, this particular form is liable to change on a regular basis. Therefore, I'd like to be able to get at all of the data that was passed through the ajax request in the form of a string that I can explode or an array.

I can then loop through the items in the array and persist them to the DB one by one (i think!).

I hope this makes sense, if I have missed anything or you would like me to explain further please let me know.

As always - all help is very much appreciated.

share|improve this question

3 Answers 3

up vote 1 down vote accepted
var $results = '';

    echo $results .= "$key = $value;";

// $results holds the posted values
share|improve this answer
  foreach($_POST as $form_key => $form_val){ }

you will not want to query each time inside this loop, however. Instead append each time to a string that you will query with afterwards.

share|improve this answer
foreach($_POST as $k => $v)

but this is pretty risky as malicious user could manually add post values to the request and do crappy stuff with your code. Make a list of allowed value maybe ;)

share|improve this answer

Your Answer


