close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Delete multiple database fields with single checkbox

Thread begun 8/02/2011 8:36 am by webVoodoo | Last modified 8/02/2011 5:12 pm by webVoodoo | 3172 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

Sign in to reply to this post

Jason ByrnesWebAssist

this is a bit beyond what we can offer support for here, if you would like help with this, I would suggest signing up for a premiere ticket where we would work with you one on one in a screen sharing session.

Sign in to reply to this post

webVoodoo

OK, thanks Jason. I may have to do that as I'm really stuck.

Paul

Sign in to reply to this post

webVoodoo

Oh, oh, oh, think I've figured this one out. As all the update action takes place in the Update Record. I dived in there and modified the code. I'll post it here as this may be of help to others.

My delete checkbox is:

<input type="checkbox" name="chk_1" value="delete" />

Modified update record code (being careful) from:

|" . "".((isset($_POST["title_1"]))?$_POST["title_1"]:"") ."" . "|

To:

|" . "".((($_POST["chk_1"] != "delete"))&&(isset($_POST["title_1"]))?$_POST["title_1"]:"") ."" . "|

...and what do you know, it seems to work !!
So only if the checkbox is ticked is the 'title' entry deleted from the database field.

The code below was found on this good forum posted by Jason. I'll paraphrase here.

When it comes to deleting the file's name from the database (using the same checkbox):

The modification is made to the line 'DefaultFileName... and don't forget the correct path to your files folder in 'UploadFolder''

$WA_UploadResult1_Params["WA_UploadResult1_1"] = array(
'UploadFolder' => "../uploads/",
'FileName' => "[FileName]",
'DefaultFileName' => "".((($_POST["chk_1"] != "delete"))?$_POST["file_1"]:"") ."",
'ResizeType' => "0",
'ResizeWidth' => "0",
'ResizeHeight' => "0",
'ResizeFillColor' => "" );
// WA_UploadResult1_1 End
// WA_UploadResult1 Params End?>

To delete the actual file from the server, add this for each checkbox:

<?php
$WA_DeleteFileResult1 = false;
if((((isset($_POST["chk_1"]))?$_POST["chk_1"]:"") != "")){
$WA_DeleteFileResult1 = WA_FileAssist_DeleteFile("../uploads/", "".((isset($_POST["file_1"]))?$_POST["file_1"]:"") ."");
}?>

I just repeated this for all the other files/titles on the page with checkboxes chk_2, chk_3, etc.

I've only just got this working and need to test thoroughly... but so far, so good.

Paul

Sign in to reply to this post

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...