Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cffile problem

Status
Not open for further replies.

ianwest

Programmer
Aug 25, 2000
3
GB
hi.

I'm having real problems using cffile in CF4.5. I have two pages, one to actually select an image and the other which has the cffile on it. what I want to do is to select an image, upload it to a specified directory, and store the image name in a table field for later use.

on the first page I have this code (the javascript was supplied by a third party, not written by me, so Ican't vouch for exactly what it's doing...)

<!--header-->

<CFQUERY DATASOURCE=&quot;seaportal&quot; NAME=&quot;admin&quot;>
SELECT * FROM venue_information
WHERE venue_name = '#URL.venue_name#'
</CFQUERY>


<CFQUERY DATASOURCE=&quot;seaportal&quot; NAME=&quot;diary&quot;>
SELECT * FROM story_info
WHERE story_id = '#URL.story_id#'
</CFQUERY>


<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function getRealFileName(frm){
var theFile = frm.story_image.value;
var fullFileName = theFile.substring(theFile.lastIndexOf('\\') + 1, theFile.length);
frm.RealFileName.value = fullFileName;
frm.submit();
}
</SCRIPT>

then in the body, the actual form that selects the image is:

<cfoutput ...>
<form action=&quot;image_add_2.cfm&quot; method=&quot;POST&quot; ENCTYPE=&quot;multipart/form-data&quot;>
<table>
<tr><td>
<input type=&quot;hidden&quot; name=&quot;story_id&quot; value=&quot;#story_id#&quot;>
<input type=&quot;hidden&quot; name=&quot;venue_name&quot; value=&quot;#venue_name#&quot;>
<input type=&quot;hidden&quot; name=&quot;RealFileName&quot; value=&quot;&quot;>
<input type=&quot;file&quot; size=&quot;30&quot; name=&quot;story_image&quot;>
</td>
</tr>

<tr>
<td width=&quot;300&quot; align=&quot;center&quot;><input type=&quot;button&quot; value=&quot;submit&quot; onclick=&quot;getRealFileName(this.form);&quot;></td>
<td width=&quot;356&quot;><input type=&quot;reset&quot; value=&quot;clear form&quot;></td>

</tr>
</table>
</form>
</cfoutput>

and on the next page I have

<cfif form.story_image NEQ &quot;&quot;>
<cfset theFile = &quot;c:\inetpub\<cffile action=&quot;UPLOAD&quot;
destination=&quot;#theFile#&quot;
nameconflict=&quot;MAKEUNIQUE&quot;
filefield=&quot;story_image&quot;
accept=&quot;image/jpg, image/jpeg, image/gif&quot;
>

<cfset var_thumbImage = &quot;#FORM.realFileName#&quot;>
<cfelse>
<cfset var_thumbImage = &quot;&quot;>
</cfif>

<CFQUERY DATASOURCE=&quot;seaportal&quot;>
INSERT INTO story_info
(story_image)
VALUES
('#var_thumbImage#')
WHERE story_id=&quot;#FORM.story_id#&quot;
</CFQUERY>

<CFQUERY DATASOURCE=&quot;seaportal&quot; NAME=&quot;admin&quot;>
SELECT * FROM venue_information
WHERE venue_name = '#FORM.venue_name#'
</CFQUERY>

<CFQUERY DATASOURCE=&quot;seaportal&quot; NAME=&quot;diary&quot;>
SELECT * FROM story_info
WHERE venue_name = '#FORM.venue_name#' AND story_id = '#FORM.story_id#'
</CFQUERY>


at the moment I'm getting an error

ODBC Error Code = 37000 (Syntax error or access violation)


[Microsoft][ODBC Microsoft Access Driver] Missing semicolon (;) at end of SQL statement.



The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (13:1) to (13:32).

(this occurs on image_add_2.cfm at the position of the query

<CFQUERY DATASOURCE=&quot;seaportal&quot;>
INSERT INTO story_info
(story_image)
VALUES
('#var_thumbImage#')
WHERE story_id = &quot;#FORM.story_id#&quot;
</CFQUERY>

anyone any ideas?

Ian
 
Hi!

on an insert you cant put a WHERE clauses...

<CFQUERY DATASOURCE=&quot;seaportal&quot;>
INSERT INTO story_info
(story_image)
VALUES
('#var_thumbImage#')
->>>>>>>>>>> WHERE story_id=&quot;#FORM.story_id#&quot;
</CFQUERY>

a good insert query would be:
<CFQUERY DATASOURCE=&quot;seaportal&quot;>
INSERT INTO story_info
(story_image)
VALUES
('#var_thumbImage#')
</CFQUERY>

no WHERE on an insert since you are simply adding a row to a table in yout db...
 
yeah, but I want to write to a field of an _existing_ ecord, and so therefore need to identify which record to write to...

or should I be using UPDATE, in which case, again, how do I identify the record to write to...

any help much appreciated

Ian
 
Yeah sure you need to use an UPDATE if you want to write to a field of an existing DB record...

ex:

<CFQUERY DATASOURCE=&quot;seaportal&quot;>
UPDATE story_info
SET story_image = '#var_thumbImage#'
WHERE story_id = &quot;#FORM.story_id#&quot;
</CFQUERY>

this would do the job...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top