troubleshooting Question

Uploading an image and inserting path into database problem...

Avatar of jasocke2
jasocke2Flag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft AccessWeb DevelopmentColdFusion Language
6 Comments1 Solution1120 ViewsLast Modified:
Im currently building a website using coldfusion, I have nearly finished but having problems with the last bit.
What I am trying to do is get the user to upload a image from there computer.
What the code below does is inserts the image from the users computer on to the server in a designated folder (/students/jasocke2/uploadedimages/), and at the same time add the link to it in the database, (/students/jasocke2/uploadedimages/IMAGE_NAME.jpeg), so that if i was to select * from image it would display the image(s) that i require, BUT it doesn't quite work like that, it uploads the image from the users computer on the server fine but when it comes to inserting the link into the database it doesnt, in the image table there is an 'ImageID' field and a 'image1' field. It inserts the auto number in but there is no ul_path in the image1 field so it's obviously trying to inser it but it doesnt.
Any ideas on how it can be resolved?
The code is below..

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<!--- first part --->
<cfif isdefined ("form.image1")>
<form action="xx1.cfm" method="post" enctype="multipart/form-data" name="upload_form" id="upload_form">
<table width="450" border="1" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
<tr bgcolor="#BACAE4">
<td>Upload An Image</td>
<td align="center"> </td>
<td align="center"><input type="file" name="Image1" id="Image1">
<input name="upload_now" type="submit" class="button" value="Upload the image"> </td>
<!--- end of first part --->
<!--- 2nd part --->
<cfif isdefined("form.Image1")>
  <cffile action="upload" filefield="Image1" destination="#ExpandPath("/students/jasocke2/uploadedimages")#" nameconflict="overwrite" accept="image/*" >
  <cfset uploadedfile = "#ExpandPath("/students/jasocke2/uploadedimages/")#">
  <p align="center">Click to confirm this is the correct logo you wish to use</p>
  <table width="450" border="1" align="center" cellpadding="6" cellspacing="0">
    <tr valign="top">
      <td><cfoutput><img src="uploadedimages/#file.serverfile#"></cfoutput></td>
      <td><cfoutput>#file.ServerFile#</cfoutput> <cfoutput>
          <form action="xx2.cfm" method="post">
            <input type="submit" name="InsertIt" value="Click to confirm">
            <input name="Image" type="hidden" value="#file.ServerFile#">
        </cfoutput> </td>
<!--- end of second part --->
<!--- third part --->
<cfif isdefined ("form.InsertIt")>
<p align="center">You inserted the image name <cfoutput>#Form.image#</cfoutput> in to your database.<br>
Upload another image.</p>
<input name="Image" type="hidden" value="#form.image#">
<cfinsert datasource="jasvasquez-access"
tablename ="Image"
<!--- end of third part --->

many thanks
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros