close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Delete multiple database fields with single checkbox

Thread began 8/02/2011 8:36 am by webVoodoo | Last modified 8/02/2011 5:12 pm by webVoodoo | 2771 views | 3 replies

webVoodoo

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('"', '&quot;', $row_WADAworks['title_1'])); ?>" />

Media 1 input
<select name="media_1" id="media_1">
<option selected><?php echo(str_replace('"', '&quot;', $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

Attached Files
Works.zip

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...