Hi
I have this code which processes a form which contains a list of files and options to either delete or save the file (via check boxes). The list of files is generated dynamically so I will never know the amount of files there are and cannot hard-code the names of the checkboxes. Instead I made the names of the fields for each file unique by generating them based on the file id:
$fieldname = "file".$fileId."field";
Now the problem is that I must also dynamically generate the names on the processing page to get the field values. This is where it stops working.
This is my code:
(On the form side; I have two fields for each file (action and description) both of them have names like "file".$id."action"....)
foreach($_SESSION['attachments'] as $attachment) {
$action_fieldname = "file_".$attachment['id']."_action";
//Check for action
if($_POST[$action_fieldname] == "0") {
$desc_fieldname = "file_".$attachment['id']."_description";
//debugging prints
echo $desc_fieldname;
echo $_POST[$desc_fieldname];
echo $_POST['file_2_description'];
//Update records, set to active
$db->Query("UPDATE attachments SET description='$_POST[$desc_fieldname]' AND status=1 WHERE id='$attachment[id]' LIMIT 1");
//Copy
copy("temp_files/".$attachment['filename'],"attachments/".$attachment['filename']);
//Delete temp file
unlink("includes/temp_file/".$attachment['filename']);
$savedFileCount++;
}
The weird thing is that $_POST[$action_fieldname] works perfect. Therefore I know that I am doing the right thing with $_POST[$desc_fieldname]; but no matter what the values for the description does not show up. As you can see; I tried to get the value for description by hardcoding the name and in that case; it shows up perfect. I compared the hard coding against $desc_fieldname and they are perfectly identical.
Maybe its something simple I cannot see; but any help would be appreciated!!!