Image upload to MySQL using CF & DW CS3???

Reply

Join Date: Jul 2008
Posts: 8
Reputation: Loki421 is an unknown quantity at this point 
Solved Threads: 0
Loki421 Loki421 is offline Offline
Newbie Poster

Image upload to MySQL using CF & DW CS3???

 
0
  #1
Jul 7th, 2008
Hi all!!!

This is my first post here so please feel free to move if it's in the wrong place :-)

Ok, i am just starting out in web development, and i have created a data entry form in DW CS3 and succesfully link it into MySQL (big deal for me!), the problems is i cannot get images to upload to the database. I am using CF locally and MySQL is also on the development machine.

So here's what i've got so far
  1. <cfset CurrentPage=GetFileFromPath(GetBaseTemplatePath())>
  2. <cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "form1">
  3. <cfquery datasource="affinity">
  4. INSERT INTO vehicle_details (vehicle_description, contract_details, available_to, deposit, business_price, personal_price, additional_infomation, manufacturer)
  5. VALUES (<cfif IsDefined("FORM.vehicle_description") AND #FORM.vehicle_description# NEQ "">
  6. <cfqueryparam value="#FORM.vehicle_description#" cfsqltype="cf_sql_clob" maxlength="200">
  7. <cfelse>
  8. ''
  9. </cfif>
  10. , <cfif IsDefined("FORM.contract_details") AND #FORM.contract_details# NEQ "">
  11. <cfqueryparam value="#FORM.contract_details#" cfsqltype="cf_sql_clob" maxlength="150">
  12. <cfelse>
  13. ''
  14. </cfif>
  15. , <cfif IsDefined("FORM.available_to") AND #FORM.available_to# NEQ "">
  16. <cfqueryparam value="#FORM.available_to#" cfsqltype="cf_sql_clob" maxlength="45">
  17. <cfelse>
  18. ''
  19. </cfif>
  20. , <cfif IsDefined("FORM.deposit") AND #FORM.deposit# NEQ "">
  21. <cfqueryparam value="#FORM.deposit#" cfsqltype="cf_sql_clob" maxlength="45">
  22. <cfelse>
  23. ''
  24. </cfif>
  25. , <cfif IsDefined("FORM.business_price") AND #FORM.business_price# NEQ "">
  26. <cfqueryparam value="#FORM.business_price#" cfsqltype="cf_sql_clob" maxlength="45">
  27. <cfelse>
  28. ''
  29. </cfif>
  30. , <cfif IsDefined("FORM.personal_price") AND #FORM.personal_price# NEQ "">
  31. <cfqueryparam value="#FORM.personal_price#" cfsqltype="cf_sql_clob" maxlength="45">
  32. <cfelse>
  33. ''
  34. </cfif>
  35. , <cfif IsDefined("FORM.additional_infomation") AND #FORM.additional_infomation# NEQ "">
  36. <cfqueryparam value="#FORM.additional_infomation#" cfsqltype="cf_sql_clob" maxlength="45">
  37. <cfelse>
  38. ''
  39. </cfif>
  40. , <cfif IsDefined("FORM.manufacturer") AND #FORM.manufacturer# NEQ "">
  41. <cfqueryparam value="#FORM.manufacturer#" cfsqltype="cf_sql_clob" maxlength="45">
  42. <cfelse>
  43. ''
  44. </cfif>
  45. )
  46. </cfquery>
  47. <cflocation url="adminwelcome.cfm">
  48. </cfif>
  49. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  50. <html xmlns="http://www.w3.org/1999/xhtml">
  51. <head>
  52. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  53. <title>admin inside</title>
  54. <style type="text/css">
  55. <!--
  56. body,td,th {
  57. font-family: Verdana, Arial, Helvetica, sans-serif;
  58. font-size: small;
  59. color: #999999;
  60. }
  61. body {
  62. background-color: #FFFFFF;
  63. background-image: url(images/Background_Affinity.jpg);
  64. background-repeat: no-repeat;
  65. }
  66. #container {
  67. width: 900px;
  68. margin-top: 60px;
  69. margin-right: auto;
  70. margin-left: auto;
  71. }
  72. #container #form1 #button2 {
  73. float: right;
  74. }
  75. -->
  76. </style>
  77. </head>
  78.  
  79. <body>
  80. <div id="container">
  81. <form id="form1" name="form1" method="POST" action="<cfoutput> #CurrentPage# </cfoutput> ">
  82. <table width="582" border="0" cellpadding="2">
  83. <tr>
  84. <td width="151"> Vehicle Description</td>
  85. <td width="230"> <label>
  86. <input type="text" name="vehicle_description" id="vehicle_description" />
  87. </label> </td>
  88. <td width="181"> <label>
  89. <input type="button" name="button5" id="button5" value="Help!" />
  90. </label> </td>
  91. </tr>
  92. <tr>
  93. <td> Contract Details</td>
  94. <td> <label>
  95. <input type="text" name="contract_details" id="contract_details" />
  96. </label> </td>
  97. <td> &nbsp;</td>
  98. </tr>
  99. <tr>
  100. <td> Available To</td>
  101. <td> <label>
  102. <input type="text" name="available_to" id="available_to" />
  103. </label> </td>
  104. <td> &nbsp;</td>
  105. </tr>
  106. <tr>
  107. <td> Deposit</td>
  108. <td> <label>
  109. <input type="text" name="deposit" id="deposit" />
  110. </label> </td>
  111. <td> &nbsp;</td>
  112. </tr>
  113. <tr>
  114. <td> Business Price</td>
  115. <td> <label>
  116. <input type="text" name="business_price" id="business_price" />
  117. </label> </td>
  118. <td> &nbsp;</td>
  119. </tr>
  120. <tr>
  121. <td> Personal Price</td>
  122. <td> <label>
  123. <input type="text" name="personal_price" id="personal_price" />
  124. </label> </td>
  125. <td> &nbsp;</td>
  126. </tr>
  127. <tr>
  128. <td> Additional Info</td>
  129. <td> <label>
  130. <input type="text" name="additional_infomation" id="additional_infomation" />
  131. </label> </td>
  132. <td> &nbsp;</td>
  133. </tr>
  134. <tr>
  135. <td height="27"> Manufacturer</td>
  136. <td> <label>
  137. <input type="text" name="manufacturer" id="manufacturer" />
  138. </label> </td>
  139. <td> &nbsp;</td>
  140. </tr>
  141. <tr>
  142. <td> Image</td>
  143. <td> <input name="userfile[]2" type="file" /> </td>
  144. <td> &nbsp;</td>
  145. </tr>
  146. <tr>
  147. <td> Brochure</td>
  148. <td> <label>
  149. <input name="userfile[]" type="file" />
  150. </label> </td>
  151. <td> &nbsp;</td>
  152. </tr>
  153. <tr>
  154. <td> &nbsp;</td>
  155. <td> &nbsp;</td>
  156. <td> &nbsp;</td>
  157. </tr>
  158. <tr>
  159. <td> <input type="submit" name="Submit" id="button" value="Save Vehicle " /> </td>
  160. <td> <label>
  161. <input type="button" name="button2" id="button2" value="Cancel" onclick="history.back()" />
  162. </label> </td>
  163. <td> &nbsp;</td>
  164. </tr>
  165. <tr>
  166. <td> <label>
  167. <input type="submit" name="button6" id="button6" value="Delete Vehicle" />
  168. </label> </td>
  169. <td> &nbsp;</td>
  170. <td> &nbsp;</td>
  171. </tr>
  172. <tr>
  173. <td> &nbsp;</td>
  174. <td> &nbsp;</td>
  175. <td> &nbsp;</td>
  176. </tr>
  177. </table>
  178. <input type="hidden" name="MM_InsertRecord" value="form1" />
  179. </form>
  180. </div>
  181. </body>
  182. </html>

So i'm thinking i must be missing a small command somewhere, but as i say i am a novice so if anyone out there can help me i'd be very grateful!!

Hope to hear from someone soon :-)

Thanks in advance!!
Last edited by peter_budo; Jul 7th, 2008 at 7:27 am. Reason: Code tag correction, closing tag is [/code] not [code]
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 72
Reputation: cmhampton is an unknown quantity at this point 
Solved Threads: 10
cmhampton's Avatar
cmhampton cmhampton is offline Offline
Junior Poster in Training

Re: Image upload to MySQL using CF & DW CS3???

 
0
  #2
Jul 7th, 2008
Couple of things here:

Use CFFILE to upload the files to the server.

(http://livedocs.adobe.com/coldfusion...2.html#4003197)

You also need to change the form's encoding type to multipart. I have updated your code below:

  1. <cfset CurrentPage=GetFileFromPath(GetBaseTemplatePath())>
  2. <cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "form1">
  3.  
  4. <!--- Set the destination folder. Use ExpandPath to properly map the folder. --->
  5. <cfset filePath = ExpandPath("/uploads") />
  6.  
  7. <!--- Upload the image file. Notice that the fileField value is not enclosed in #s. This is the correct syntax --->
  8. <cffile action="upload" filefield="form.imageFile" nameconflict="makeunique" destination="#filePath#" result="imageUpload" />
  9.  
  10. <!--- Upload the brochure file. --->
  11. <cffile action="upload" filefield="form.brochureFile" nameconflict="makeunique" destination="#filePath#" result="brochureUpload" />
  12.  
  13. <cfquery datasource="affinity">
  14. INSERT INTO
  15. vehicle_details
  16. (vehicle_description, contract_details, available_to, deposit, business_price, personal_price, additional_infomation, manufacturer, imageFile, brochureFile)
  17. VALUES (
  18. <cfif IsDefined("FORM.vehicle_description") AND FORM.vehicle_description NEQ "">
  19. <cfqueryparam value="#FORM.vehicle_description#" cfsqltype="cf_sql_clob" maxlength="200">
  20. <cfelse>
  21. ''
  22. </cfif>,
  23. <cfif IsDefined("FORM.contract_details") AND FORM.contract_details NEQ "">
  24. <cfqueryparam value="#FORM.contract_details#" cfsqltype="cf_sql_clob" maxlength="150">
  25. <cfelse>
  26. ''
  27. </cfif>,
  28. <cfif IsDefined("FORM.available_to") AND FORM.available_to NEQ "">
  29. <cfqueryparam value="#FORM.available_to#" cfsqltype="cf_sql_clob" maxlength="45">
  30. <cfelse>
  31. ''
  32. </cfif>,
  33. <cfif IsDefined("FORM.deposit") AND FORM.deposit NEQ "">
  34. <cfqueryparam value="#FORM.deposit#" cfsqltype="cf_sql_clob" maxlength="45">
  35. <cfelse>
  36. ''
  37. </cfif>,
  38. <cfif IsDefined("FORM.business_price") AND FORM.business_price NEQ "">
  39. <cfqueryparam value="#FORM.business_price#" cfsqltype="cf_sql_clob" maxlength="45">
  40. <cfelse>
  41. ''
  42. </cfif>,
  43. <cfif IsDefined("FORM.personal_price") AND FORM.personal_price NEQ "">
  44. <cfqueryparam value="#FORM.personal_price#" cfsqltype="cf_sql_clob" maxlength="45">
  45. <cfelse>
  46. ''
  47. </cfif>,
  48. <cfif IsDefined("FORM.additional_infomation") AND FORM.additional_infomation NEQ "">
  49. <cfqueryparam value="#FORM.additional_infomation#" cfsqltype="cf_sql_clob" maxlength="45">
  50. <cfelse>
  51. ''
  52. </cfif>,
  53. <cfif IsDefined("FORM.manufacturer") AND FORM.manufacturer NEQ "">
  54. <cfqueryparam value="#FORM.manufacturer#" cfsqltype="cf_sql_clob" maxlength="45">
  55. <cfelse>
  56. ''
  57. </cfif>,
  58. <cfif IsDefined("imageUpload") AND Len(Trim(imageUpload)) NEQ 0>
  59. <cfqueryparam value="#imageUpload.ServerFile#" cfsqltype="cf_sql_varchar">
  60. <cfelse>
  61. ''
  62. </cfif>,
  63. <cfif IsDefined("brochureUpload") AND Len(Trim(brochureUpload)) NEQ 0>
  64. <cfqueryparam value="#brochureUpload.ServerFile#" cfsqltype="cf_sql_varchar">
  65. <cfelse>
  66. ''
  67. </cfif>
  68. )
  69. </cfquery>
  70.  
  71. <cflocation url="adminwelcome.cfm">
  72.  
  73. </cfif>
  74.  
  75. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  76. <html xmlns="http://www.w3.org/1999/xhtml">
  77. <head>
  78. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  79. <title>admin inside</title>
  80. <style type="text/css">
  81. <!--
  82. body,td,th {
  83. font-family: Verdana, Arial, Helvetica, sans-serif;
  84. font-size: small;
  85. color: #999999;
  86. }
  87. body {
  88. background-color: #FFFFFF;
  89. background-image: url(images/Background_Affinity.jpg);
  90. background-repeat: no-repeat;
  91. }
  92. #container {
  93. width: 900px;
  94. margin-top: 60px;
  95. margin-right: auto;
  96. margin-left: auto;
  97. }
  98. #container #form1 #button2 {
  99. float: right;
  100. }
  101. -->
  102. </style>
  103. </head>
  104.  
  105. <body>
  106. <div id="container">
  107.  
  108. <!--- Set the form encoding type to multipart. --->
  109. <form id="form1" name="form1" method="POST" enctype="multipart/form-data" action="<cfoutput> #CurrentPage# </cfoutput> ">
  110. <table width="582" border="0" cellpadding="2">
  111. <tr>
  112. <td width="151"> Vehicle Description</td>
  113. <td width="230"> <label>
  114. <input type="text" name="vehicle_description" id="vehicle_description" />
  115. </label> </td>
  116. <td width="181"> <label>
  117. <input type="button" name="button5" id="button5" value="Help!" />
  118. </label> </td>
  119. </tr>
  120. <tr>
  121. <td> Contract Details</td>
  122. <td> <label>
  123. <input type="text" name="contract_details" id="contract_details" />
  124. </label> </td>
  125. <td> &nbsp;</td>
  126. </tr>
  127. <tr>
  128. <td> Available To</td>
  129. <td> <label>
  130. <input type="text" name="available_to" id="available_to" />
  131. </label> </td>
  132. <td> &nbsp;</td>
  133. </tr>
  134. <tr>
  135. <td> Deposit</td>
  136. <td> <label>
  137. <input type="text" name="deposit" id="deposit" />
  138. </label> </td>
  139. <td> &nbsp;</td>
  140. </tr>
  141. <tr>
  142. <td> Business Price</td>
  143. <td> <label>
  144. <input type="text" name="business_price" id="business_price" />
  145. </label> </td>
  146. <td> &nbsp;</td>
  147. </tr>
  148. <tr>
  149. <td> Personal Price</td>
  150. <td> <label>
  151. <input type="text" name="personal_price" id="personal_price" />
  152. </label> </td>
  153. <td> &nbsp;</td>
  154. </tr>
  155. <tr>
  156. <td> Additional Info</td>
  157. <td> <label>
  158. <input type="text" name="additional_infomation" id="additional_infomation" />
  159. </label> </td>
  160. <td> &nbsp;</td>
  161. </tr>
  162. <tr>
  163. <td height="27"> Manufacturer</td>
  164. <td> <label>
  165. <input type="text" name="manufacturer" id="manufacturer" />
  166. </label> </td>
  167. <td> &nbsp;</td>
  168. </tr>
  169. <tr>
  170. <td> Image</td>
  171. <td> <input name="imageFile" type="file" /> </td>
  172. <td> &nbsp;</td>
  173. </tr>
  174. <tr>
  175. <td> Brochure</td>
  176. <td> <label>
  177. <input name="brochureFile" type="file" />
  178. </label> </td>
  179. <td> &nbsp;</td>
  180. </tr>
  181. <tr>
  182. <td> &nbsp;</td>
  183. <td> &nbsp;</td>
  184. <td> &nbsp;</td>
  185. </tr>
  186. <tr>
  187. <td> <input type="submit" name="Submit" id="button" value="Save Vehicle " /> </td>
  188. <td> <label>
  189. <input type="button" name="button2" id="button2" value="Cancel" onclick="history.back()" />
  190. </label> </td>
  191. <td> &nbsp;</td>
  192. </tr>
  193. <tr>
  194. <td> <label>
  195. <input type="submit" name="button6" id="button6" value="Delete Vehicle" />
  196. </label> </td>
  197. <td> &nbsp;</td>
  198. <td> &nbsp;</td>
  199. </tr>
  200. <tr>
  201. <td> &nbsp;</td>
  202. <td> &nbsp;</td>
  203. <td> &nbsp;</td>
  204. </tr>
  205. </table>
  206. <input type="hidden" name="MM_InsertRecord" value="form1" />
  207. </form>
  208. </div>
  209. </body>
  210. </html>

I hope this helps. Let me know if you need anything.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 8
Reputation: Loki421 is an unknown quantity at this point 
Solved Threads: 0
Loki421 Loki421 is offline Offline
Newbie Poster

Re: Image upload to MySQL using CF & DW CS3???

 
0
  #3
Jul 7th, 2008
That's great!! Thanks, really appreciate the time you've taken for me.

Unfortunatly i'm getting this error now when i try to use it:

  1. The web site you are accessing has experienced an unexpected error.
  2. Please contact the website administrator.
  3.  
  4. The following information is meant for the website developer for debugging purposes.
  5.  
  6. Error Occurred While Processing Request
  7. Complex object types cannot be converted to simple values.
  8. The expression has requested a variable or an intermediate expression result as a simple value, however, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.
  9. The most likely cause of the error is that you are trying to use a complex value as a simple one. For example, you might be trying to use a query variable in a cfif tag.
  10.  
  11.  
  12. Resources:
  13. Enable Robust Exception Information to provide greater detail about the source of errors. In the Administrator, click Debugging & Logging > Debug Output Settings, and select the Robust Exception Information option.
  14. Check the ColdFusion documentation to verify that you are using the correct syntax.
  15. Search the Knowledge Base to find a solution to your problem.
  16.  
  17.  
  18. Browser Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; YPC 3.2.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 1.1.4322; InfoPath.1)
  19. Remote Address 127.0.0.1
  20. Referrer <a rel="nofollow" class="t" href="http://localhost:8500/affinity_new_site_testing/updatedcode.cfm" target="_blank">http://localhost:8500/affinity_new_s...pdatedcode.cfm</a>
  21. Date/Time 07-Jul-08 07:17 PM

Don't suppose you know what's up with it do you? :-)
Last edited by peter_budo; Jul 9th, 2008 at 8:10 am. Reason: Please avoid using an excessive amount of [bbcode] to alter font styles
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 72
Reputation: cmhampton is an unknown quantity at this point 
Solved Threads: 10
cmhampton's Avatar
cmhampton cmhampton is offline Offline
Junior Poster in Training

Re: Image upload to MySQL using CF & DW CS3???

 
0
  #4
Jul 7th, 2008
Go into the ColdFusion Administrator and turn on Robust Debugging. Check the line number and let me know where the error is occurring. I didn't get a chance to actually test this, so I probably missed something.
Last edited by cmhampton; Jul 7th, 2008 at 4:44 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC