10 Replies Latest reply on Dec 4, 2007 10:21 AM by CFMXPrGrmR

    Deleting a record and the uploaded file problem

    Irish-Phoenix Level 1
      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
        • 1. Re: Deleting a record and the uploaded file problem
          Level 7
          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
          • 2. Re: Deleting a record and the uploaded file problem
            paross1 Level 2
            Which process doesn't seem to be working? The database deletion, the file deletion, or both?

            Phil
            • 3. Re: Deleting a record and the uploaded file problem
              Irish-Phoenix Level 1
              The file deletion isn't working.

              Did I script it wrong?
              • 4. Deleting a record and the uploaded file problem
                CFMXPrGrmR Level 2
                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#">
                • 5. Re: Deleting a record and the uploaded file problem
                  Irish-Phoenix Level 1
                  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?
                  • 6. Re: Deleting a record and the uploaded file problem
                    Irish-Phoenix Level 1
                    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
                    • 7. Deleting a record and the uploaded file problem
                      paross1 Level 2
                      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
                      • 8. Re: Deleting a record and the uploaded file problem
                        Irish-Phoenix Level 1
                        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?
                        • 9. Re: Deleting a record and the uploaded file problem
                          paross1 Level 2
                          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#">
                          • 10. Re: Deleting a record and the uploaded file problem
                            CFMXPrGrmR Level 2
                            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#">