ron tornambe ron tornambe - 1 year ago 64
PHP Question

Why isn't PHP receiving an array of values?

I am passing multiple values to PHP with the same name using ajax. But when I dump the array, only the last value is shown.

The serialized form:



"genres=" . var_dump(array($_REQUEST["genres"])) . "\n";

array (size=1)

0 => string '24' (length=2)


$("#form-enablers").on("submit", function () {
var data = $("#form-enablers").serialize() + "&action=search";
ajax('post', 'php/enablers.php', data, success, "Error searching: ");
function success(table) {
$("#writers-list").css({ "display": "block" });

Answer Source

If you want to pass an array of values in a request, a special syntax is required. You need to add brackets [] to attribute name in order to put all attributes in an array.

In your case the serialized data should look like the following:


This way $_REQUEST['genres'] will contain an array of values instead of a single value.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download