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!

Uploading Images along with Form Information

Status
Not open for further replies.

jasonkeller

Programmer
May 23, 2001
16
US
I am currently writing a coldfusion with access database web site. I am using a form and then posting that form information to another page for processing that contains an CFINSERT for all the info inserted into the database. It works fine.

Is it possible to use along with the CFINSERT, a <cffile action=&quot;UPLOAD&quot; filefield=&quot;picture&quot;
destination=&quot;d:&quot; nameconflict=&quot;MAKEUNIQUE&quot;> to tag along with the form information a large and thumbnail image?

I have the database generating an autonumber for every new entry from the form.





 
Yeah, its completely possible. Its pretty easy :

<cftransaction>

<CFQUERY NAME=&quot;whatever&quot; DATASOURCE=&quot;your_dsn&quot;>
<cffile action=&quot;UPLOAD&quot;
filefield=&quot;picture&quot;
destination=&quot;d:&quot;
nameconflict=&quot;MAKEUNIQUE&quot;>


INSERT INTO your_table_name (NAME,SUBJECT,DESCRIPTION,FILE)
'these are your field names in the database
values ('#txtName#','#txtSubject#','#txtDesc#','#File.ServerFile#')
'these are the names of your textboxes on the form itself
'File.ServerFile is what CF uses as the name of the saved file
</cfquery>
</cftransaction>

That should work.
 
I am receiving a CFFILE error now. I am kinda getting it but still unsure where to put the cftransaction tag.
Below is a small piece of my form and my processing page which returns the user back to an admin screen where I query the database for all the inputs.

After the info is input by the user it goes to a processinfo page and I think this is where my problem is. Do I need that extra page?

form.cfm
------------------------------------------------------------
<form action=&quot;processinfo.cfm&quot; method=&quot;POST&quot;>

<FONT FACE=&quot;Arial&quot; size=2><B>Add / Change:</B></FONT><BR>
<input name=&quot;picture&quot; type=&quot;file&quot; size=&quot;20&quot;>br>

<table align=center>
<tr>
<td><FONT FACE=&quot;Arial&quot; SIZE=2>Product Code/ID</FONT></td>
<td><input type=&quot;Text&quot; name=&quot;product_id&quot;></td>
</tr>
<tr>
<td><FONT FACE=&quot;Arial&quot; SIZE=2>Product Name</FONT></td>
<td><input type=&quot;Text&quot; name=&quot;product_name&quot;></td>
</tr>
</table>
<input type=&quot;Submit&quot; value=&quot;Save New Product&quot;>
</form>
------------------------------------------------------------

processinfo.cfm
&quot;This is my complete processing form-the values are not all listed above as they are below&quot;
------------------------------------------------------------
<cftransaction>

<CFQUERY DATASOURCE=&quot;mjgrant&quot;>

INSERT INTO products

(file,product_id,product_name,category,subcategory,price,size,setup_cost,minorder,description,colors)

VALUES

('#form.colors#','#form.description#','#form.minorder#','#form.setup_cost#','#form.size#','#form.rpice#','#form.subcategory#','#form.product_id#','#form.product_name#','#form.category#','#File.ServerFile#')

</CFQUERY>

</cftransaction>


<HTML>
<HEAD>
<TITLE></TITLE>
<meta http-equiv=&quot;refresh&quot; content=&quot;1;url=admin_secure.cfm&quot;>
</HEAD>

<BODY>
<CENTER><FONT COLOR=black FACE=&quot;Arial&quot;><h2>Adding new info. . .Please Wait</h2></FONT></CENTER>

</BODY>
</HTML>
 
Aight, try doing this. First of all in your form tag :

<form ENCTYPE=&quot;MULTIPART/FORM-DATA&quot; action=&quot;processinfo.cfm&quot; method=&quot;POST&quot;>

And as far as the <cftransaction> tag goes, it looks fine as is. Try fixing that form issue and see if that works.
 
Also, since your form isn't on the same page, take the 'form.' out of your variables. For example, instead of
'#form.colors#','#form.description#', try just #colors#, #description#, etc
 
Ok, I have tried them all and I am still getting some errors.

Here is my link to the site:
Look towards the bottom...there is an &quot;Administration Login&quot;
Click there. login is &quot;mjgrant&quot; password is &quot;grantpassword&quot; and click on Add New

Check it out if it helps. Here is a shorter version with 3 inputs and image and two text inputs.

form.cfm
------------------------------------------------------------
<form action=&quot;processinfo.cfm&quot; method=&quot;POST&quot;>

<FONT FACE=&quot;Arial&quot; size=2><B>Add / Change:</B></FONT><BR>
<input name=&quot;mainpicture_id&quot; type=&quot;file&quot; size=&quot;20&quot;>br>

<table align=center>
<tr>
<td><FONT FACE=&quot;Arial&quot; SIZE=2>Product Code/ID</FONT></td>
<td><input type=&quot;Text&quot; name=&quot;product_id&quot;></td>
</tr>
<tr>
<td><FONT FACE=&quot;Arial&quot; SIZE=2>Product Name</FONT></td>
<td><input type=&quot;Text&quot; name=&quot;product_name&quot;></td>
</tr>
</table>
<input type=&quot;Submit&quot; value=&quot;Save New Product&quot;>
</form>
------------------------------------------------------------


processinfo.cfm
&quot;This is my complete processing form-the values are not all listed above as they are below&quot;
------------------------------------------------------------
<cftransaction>

<CFQUERY DATASOURCE=&quot;mjgrant&quot;>

INSERT INTO products

(product_id,product_name,mainpicture_id)

VALUES

('#form.product_id#','#form.product_name#','#File.ServerFile#')

</CFQUERY>

</cftransaction>


<HTML>
<HEAD>
<TITLE></TITLE>
<meta http-equiv=&quot;refresh&quot; content=&quot;1;url=admin_secure.cfm&quot;>
</HEAD>

<BODY>
<CENTER><FONT COLOR=black FACE=&quot;Arial&quot;><h2>Adding new info. . .Please Wait</h2></FONT></CENTER>

</BODY>
</HTML>
 
Never mind my last post, I have it working.

Next question is???

How to I input 2 images like a mainpicture and a thumbnail picture?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top