Send all jQuery array values to php and insert into the database

Otherwise, if you want to keep default submit action of the form (with page reloading) you have to change way you’re using to pass array with the form.

To do that, add hidden field to the form:

<input type="hidden" name="selectedDaysJSON" value="">

and make form to put JSON representation of the array into that field on submit:

$("input[type='submit']").click(function(e) {
    $('input[name=selectedDaysJSON]').val( JSON.stringify(selectedDays) );
});

PHP code will remain the same in this case

1 Like