• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Deleting a record and the uploaded file problem

Contributor ,
Dec 04, 2007 Dec 04, 2007

Copy link to clipboard

Copied

Hello, I need to set up a delete function for a Database, and am trying to set it up so that the file that was uploaded to the server and is listed in the DB table, gets deleted with it. How would I write this out? here is what I have so far:

<cfquery name="DeleteRecord" dataSource="#sitedatasource#" maxRows=1>
DELETE
FROM feature
WHERE feature.ID = #Form.ID#
</cfquery>
<cffile action="delete" destination="c:/website/img/feature" file="#feature.MYFile#">
<cflocation url="feature_RecordView.cfm">

This doesn't seem to work, what am I doing wrong here? How would I write it out to make this feature work properly?

Thanks

Phoenix
TOPICS
Advanced techniques

Views

586

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 04, 2007 Dec 04, 2007

Copy link to clipboard

Copied

1) check the cfml reference for cffile action="delete" - youve got it wrong.
2) a presume the name of the file to delete IS coming from somewhere...
not the DELETE query... some query apparently named "features"... i
wonder where it is... ;)

---
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Dec 04, 2007 Dec 04, 2007

Copy link to clipboard

Copied

Which process doesn't seem to be working? The database deletion, the file deletion, or both?

Phil

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 04, 2007 Dec 04, 2007

Copy link to clipboard

Copied

The file deletion isn't working.

Did I script it wrong?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 04, 2007 Dec 04, 2007

Copy link to clipboard

Copied

Just a little tip... if possible use a yes/no or bit field type and flag it for active/inactive instead of actually deleting. Once it's gone, it's gone. I've had a few cases where actually saving the record and just 'deactivating' it was a better choice.

Check the CF log files for your error, you may not have access to delete on your web server.

You should also look into using query param in your WHERE clause. It's safer.

WHERE feature.id = <cfqueryparam cfsqltype="cf_sql_integer" value="#form.id#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 04, 2007 Dec 04, 2007

Copy link to clipboard

Copied

this is my error:

Error Diagnostic Information

An error occurred while evaluating the expression:


"#feature.MYFile#"



Error near line 153, column 78.
Error resolving parameter FEATURE.MYFILE


ColdFusion was unable to determine the value of the parameter. This problem is very likely due to the fact that either:

You have misspelled the parameter name, or
You have not specified a QUERY attribute for a CFOUTPUT, CFMAIL, or CFTABLE tag.


The error occurred while processing an element with a general identifier of (CFFILE), occupying document position (153:2) to (153:94) in the template file c:\websites\x9vdzd\admin\Action.cfm.

Here is the code I am using, I changed it from your advice:

<cfquery name="DeleteRecord" dataSource="#sitedatasource#" maxRows=1>
DELETE
FROM feature
WHERE feature.id = <cfqueryparam cfsqltype="cf_sql_char" value="#form.id#">
</cfquery>
<cffile action="delete" destination="c:/websites/x9vdzd/img/feature" file="#feature.MYFile#">
<cflocation url="feature_RecordView.cfm">

Any suggestions?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 04, 2007 Dec 04, 2007

Copy link to clipboard

Copied

would this be how the delete function is supposed to be?

<cfquery name="deleteFile" datasource="#sitedatasource#" username="#siteUserID#" password="#sitePassword#">
select feature.title, feature.Body, feature.MYFile
FROM feature
</cfquery>
<cffile action="delete" destination="c:/websites/x9vdzd/img/feature" file="#feature.MYFile#">
<cfquery name="DeleteRecord" dataSource="#sitedatasource#" maxRows=1>
DELETE
FROM feature
WHERE feature.id = <cfqueryparam cfsqltype="cf_sql_char" value="#form.id#">
</cfquery>

or is this still wrong?

Phoenix

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Dec 04, 2007 Dec 04, 2007

Copy link to clipboard

Copied

How about using #deleteFile.MYFile# instead of #feature.MYFile#? Your variable requires the query name, not the table name.

Also, this query is going to return all of the rows from the feature table. Don't you think that you should include a WHERE clause to restrict what your query is returning?

<cfquery name="deleteFile" datasource="#sitedatasource#" username="#siteUserID#" password="#sitePassword#">
select feature.title, feature.Body, feature.MYFile
FROM feature
</cfquery>

Phil

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 04, 2007 Dec 04, 2007

Copy link to clipboard

Copied

if I use #deleteFile.MYFile# use a where statement like this
then use it in the cffile delete like this?
<cfquery name="deleteFile" datasource="#sitedatasource#" username="#siteUserID#" password="#sitePassword#">
SELECT feature.title, feature.Body, feature.MYFile
FROM feature
WHERE WHERE feature.id = <cfqueryparam cfsqltype="cf_sql_char" value="#form.id#">
</cfquery>
<cffile action="delete" destination="c:/websites/x9vdzd/img/feature" file="#feature.MYFile#">
<cfquery name="DeleteRecord" dataSource="#sitedatasource#" maxRows=1>
DELETE
FROM feature
WHERE feature.id = <cfqueryparam cfsqltype="cf_sql_char" value="#form.id#">
</cfquery>

<cffile action="delete" destination="c:/websites/x9vdzd/img/feature" file="#deleteFile.MYFile#">

Is this what you mean?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Dec 04, 2007 Dec 04, 2007

Copy link to clipboard

Copied

Something like this....

<cfquery name="deleteFile" datasource="#sitedatasource#" username="#siteUserID#" password="#sitePassword#">
SELECT feature.title, feature.Body, feature.MYFile
FROM feature
WHERE feature.id = <cfqueryparam cfsqltype="cf_sql_char" value="#form.id#">
</cfquery>

<cfquery name="DeleteRecord" dataSource="#sitedatasource#" maxRows=1>
DELETE
FROM feature
WHERE feature.id = <cfqueryparam cfsqltype="cf_sql_char" value="#form.id#">
</cfquery>

<cffile action="delete" destination="c:/websites/x9vdzd/img/feature" file="#deleteFile.MYFile#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 04, 2007 Dec 04, 2007

Copy link to clipboard

Copied

LATEST
Just a note for the cfqueryparam. The cfsqltype="cf_sql_char" is if your field is a character type. If it's numeric then change this to <cfqueryparam cfsqltype="numeric" value="#form.id#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation