0 Replies Latest reply on Dec 2, 2007 11:53 AM by Irish-Phoenix

    Editing a record and adding cffile, please help

    Irish-Phoenix Level 1
      Hello;
      I am writting an editor page for a web site. I am trying to add cffile to the edit function. This page acts as 2 ways of editing the DB records, it can add a new one, and it can edit an exisitng one.

      What I am trying to do is this:

      1. When you add a record, you can upload an image and add all the content in the other feilds, click the ok button and it will upload the file, and add the file name to the DB table.

      2. when you want to edit the record, the file upload feild is blank and under it is the name of the file being used, so you can upload a new file and change the one that record is using.

      Here is my code so far, I don't have it set to do number 2. yet, I am not sure how to do it and same goes for uploading the file in the action script and making it add it to the DB record.

      edit page code:

      <cfset FormFieldList = "title,image,discription,body">

      <cfif ParameterExists(URL.RecordID)>
      <cfquery name="featRec" dataSource="creative" maxRows=1>
      SELECT feature.title, feature.image, feature.discription, feature.body, feature.ID AS ID_Field
      FROM feature
      <cfif ParameterExists(URL.RecordID)>
      WHERE feature.ID = #URL.RecordID#
      </cfif>
      </cfquery>

      <cfif not ListFind( FormFieldList, "ID" )>
      <cfset FormFieldList = ListAppend( FormFieldList, "ID" )>
      </cfif>


      <cfset title_Value = '#featRec.title#'>

      <cfset image_Value = '#featRec.image#'>

      <cfset discription_Value = '#featRec.discription#'>

      <cfset body_Value = '#featRec.body#'>


      <cfelse>


      <cfset title_Value = ''>

      <cfset image_Value = ''>

      <cfset discription_Value = ''>

      <cfset body_Value = ''>


      </cfif>
      <head>
      </head>
      <body>
      <cfoutput query="featRec">
      <form action="Action.cfm" method="post" name="content" id="content" onsubmit="saveIt()">
      <input type="hidden" name="FieldList" value="#FormFieldList#">
      <cfif ParameterExists(URL.RecordID)>
      <input type="hidden" name="RecordID" value="#URL.RecordID#">
      <input type="hidden" name="ID" value="#URL.RecordID#">
      </cfif>
      <input type="text" name="title" class="textInputs" value="#title_Value#" maxLength="510">
      <!--- this is the file uploader --->
      <input type="file" name="MYFile">
      <cfif MYFile IS defined>
      #file#
      </cfif>
      <!--- end file uploader code --->
      <input type="text" name="image" class="textInputs" value="#image_Value#" maxLength="510">
      <input type="text" name="discription" class="textInputs" value="#discription_Value#" maxLength="510">
      <textarea cols="" rows="" name="PDSeditor" style="display: none">#Body_Value#</textarea>
      </cfoutput>
      <input type="submit" class="formButtons" name="feat_OK" value=" OK ">
      <input type="submit" class="formButtons" name="feat_Cancel" value="Cancel">
      </form>


      Action Script:

      <cffile Action="upload" filefield="uploadfile" destination=" http://www.myurl.com/img/feature" nameconflict="MAKEUNIQUE">
      <cfif ParameterExists(Form.RecordID)>
      <cfupdate dataSource="#sitedatasource#" tableName="feature" formFields="#Form.FieldList#">
      <cflocation url="feature_RecordView.cfm>

      <cfelse>
      <cfquery datasource="#sitedatasource#" dbtype="ODBC" username="#siteUserID#" password="#sitePassword#">
      INSERT INTO feature (title, image, discription, Body)
      VALUES ('#form.title#', '#form.image#', '#form.description#', '#form.PDSeditor#')
      </cfquery>
      <cflocation url="feature_RecordView.cfm>
      </cfif>

      <!--- End code --->

      Can anyone help me? I am confused on how to make this work.

      Thank you.

      Phoenix