Hi,
Ok, so I'm making a registration form system, where I can create new registration forms for the users to pick a date etc.
In my form I can add and remove text fields via Javascript - to add additional dates etc. so I don't know if I'll be submitting 3 fields or 15.
The could look like this:
<input type="hidden" name="session_id[]" value="<?php echo $session_id; ?>">
<input type="text" name="picked_date[]">
<input type="text" name="picked_room[]">
They are put in a big array:
De bliver smidt i et stort array:
$n=0;
foreach ($session_id as $_session_id) {
$bigar[$n][1] = $_session_id;
$n++;
}
$n=0;
foreach ($picked_date as $_picked_date) {
$bigar[$n][2] = $_picked_date;
$n++;
}
$n=0;
foreach ($picked_room as $_picked_room) {
$bigar[$n][3] = $_picked_room;
$n++;
}
$n=0;
which is then updated in the database using:
foreach ($bigar as $part)
{
mysql_query("UPDATE...
}
Right - so far so good. The updating works fine with existing fields, but if I remove some of the fields (via JS) it obviously only updates the remaining in the array. The left out will be ignored. On the same note I would like to add fields as well, so - the bottom line - I want to:
- UPDATE rows, where the ID is in the array
- DELETE existing rows, WHERE the ID is NOT in the array
- CREATE new rows for the new fields in the array (not having an ID)
How can this be achieved? Hope someone can help...