Delete multiple database fields with single checkbox
I'm realising this will take a bit of explaining, so have attached all (I hope) relevant files as maybe easier to understand when seen.
Basically, I have a page 'works.php' which displays up to 6 files (plus 3 embed videos) which can be either images, audio or PDFs in any combination, each having a title.
When DataAssist created the Insert page (works_insert.php), it contained a very long list of input fields, so I devised a way of choosing the Media Type from a drop down which enabled me to reduce the number of fields to 6. Each containing the Title, File Upload and Media Type.
Works.php then fetches the Title, File Name and File Type for each uploaded file from the 'works' table. File Type inserts the correct opening and closing tags for each media type ie, <image> (images) or <embed> (audio) or <a> (PDF) from the database 'media' table (and is never updated)
This is where things got tricky. I wanted to be able to delete individual files using checkboxes on the Update page (works_update.php) which, after some forum searching, have been able to delete the file name from the database (have only modified code for File 1 as a test so far) and also delete the file on the server but I also want the checkbox to delete the file's Title and set the File Type to insert 'Choose' to the database 'media' field in the 'works' table.
I tried using javascript 'if else' with hidden fields but don't think that's the right way to do this but here is the code I used anyway.
Note: You may want to ignore this javascript method as probably not the way to go and it didn't work anyway.
For the first checkbox (repeated for other 5 checkboxes as chk_2, chk_3, etc).
Checkbox name chk_1
<script type="text/javascript">
function validate1(chk_1) {
if (chk_1.checked == 1)
get_title_1.value = '', get_media_1.value = 'Choose';
else
get_title_1.value = title_1.value, get_media_1.value = media_1.value;
}
</script>
Hidden fields (Updating record from these fields).
<input type="hidden" name="get_title_1" id="get_title_1" />
<input type="hidden" name="get_media_1" id="get_media_1" />
Title 1 input field
<input type="text" name="title_1" id="title_1" value="<?php echo(str_replace('"', '"', $row_WADAworks['title_1'])); ?>" />
Media 1 input
<select name="media_1" id="media_1">
<option selected><?php echo(str_replace('"', '"', $row_works['media_1'])); ?></option>
<option value="image">Image</option>
<option value="mp3">MP3</option>
<option value="pdf">PDF</option>
</select>
Then added onclick="return validate1(chk_1),loadSubmit();" to the Update button.
I removed all this javascript from the page before attaching to post to simplify the page.
Hope this is not too confusing. Any help is of course greatly appreciated. Would love to get this final step working.
Paul