Cffileupload and inserting a database record problem

I would very much like to use the multi-file uploader on a site I’m working on but I need to also insert a record to the application database connecting the uploaded file with the property it belongs to. Unfortunately I’m struggling to find information that will help me get the page working the way I want it to. I want to use cfselect to allow the admin staff to choose the property’s name from the drop-down list and pass on the property name to the action page along with the uploaded files. The problem is that an error is generated because the action file needs to compare the as yet unsubmitted property name with the database property names. Can you suggest how I might go about getting this to work? Here’s the code:

Form
<cfquery name=“propertylist” datasource=“*****”>
SELECT propertyname
FROM properties
</cfquery>

<cfform action=“cffileupload_action.cfm”>
<!— Choose Property to Upload Photos for —>
<div id=“chooseproperty”>
<fieldset id=“chooseproperty”>
<legend><span>Choose Property</span></legend>
<cfselect name=“propertyname” query=“propertylist” display=“propertyname” queryposition=“below”></cfselect><br />
</fieldset>
</div>
</cfform>

<!— Choose Photos to Upload —>
<div id=“photoupload”>
<fieldset id=“photoupload”>
<legend><span>Upload Photos</span></legend>
<cffileupload url=“cffileupload_action_orig.cfm?#urlEncodedFormat(session.urltoken)#&propertyname=#url.propertyname#” extensionfilter=“.jpg, .png, .jpeg” maxuploadsize=“1” title=“Photo Uploader” width=“600” addbuttonlabel=“Select Photos” clearbuttonlabel=“Remove All Photos” deletebuttonlabel=“Remove Photo” />
<input type=“submit” value=“Submit” id=“controls”>
</fieldset>
</div>

Action Page
<cffile action=“uploadall” destination=“/Applications/MAMP/htdocs/*******/properties/#Form.propertyname#/images” nameConflict=“Overwrite”>

<cfquery name=“lookupID” datasource=“*****”>
SELECT propID
FROM properties
WHERE propertyname = “#Form.propertyname#”
</cfquery>

<cfquery name=“addfilename” dataSource=“*****”>
INSERT INTO images(imagefilename, propID)
VALUES(‘#CFFILE.SERVERFILE#’, ‘<cfoutput query=“lookupID”>#propID#</cfoutput>’)
</cfquery>

I’m hoping someone may know how this could be done?

After your lookupID query use <cfset> to set the propID and then use that in your query

<cfset propID="#lookupID.propID#>

<cfquery name=“addfilename” dataSource=“*****”>
INSERT INTO images(imagefilename, propID)
VALUES(‘#CFFILE.SERVERFILE#’, ‘#propID#’)
</cfquery>

Have tried your suggestion and, as the code currently is, this doesn’t work, but I’ve also used your suggestion with another form I’m working on and, if I combine your suggestion with putting the cfselect into a separate form submitted to itself rather than the cffileupload action page, and use a cfif statement to make sure the propertyname is passed for use in the next action, then I can get the propID with your code suggestion and, hopefully, that will work when it’s all passed on to the cffileupload action.

For now, I’ve added another page to select the propertyname first and then pass it to the cffileupload form. It works and it’ll have to do for now but I want it to work as originally planned and I’ll be trying to get it working as suggested above after I’ve got the rest of the changes to the site done and uploaded. Thanks for your help and, if I get it to work, I’ll post back, perhaps with the code so that someone else can benefit.