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
Web DevelopmentColdFusion LanguageMicrosoft Access
6 Comments2 Solutions1120 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

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 2 Answers and 6 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 2 Answers and 6 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004