Uploading photos to the images folder in the site root and adding the info to mysql

Discussion in 'Programming' started by cumupkid, Jan 22, 2008.

  1. #1
    I am trying to create a form that will allow me to upload photos to the images folder and add the information to the mysql database.

    No restrictions on file size or tpe.

    Am using coldfusion 8, dreamweaver, and my sql.
     
    cumupkid, Jan 22, 2008 IP
  2. cumupkid

    cumupkid Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    So I figured out how to create an uplod form using coldfusion and dreamweaver 8 but...

    1) i can not get a .jpg file to upload, but can get a .gif file to upload. Maybe it has something to do with the file size.

    2) I need to be able to add the photo information to Mysql at the same time I upload the file.

    Any help would be appreciated, I am including the code i have.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <link href="../assets/intheworks.css" rel="stylesheet" type="text/css" />
    <body>
    <cfif isdefined ("form.upload_now")>

    <cffile accept="image/gif, image/jpg" action="upload" destination="C:\ColdFusion8\wwwroot\intheworksphotoco\images\" filefield="ul_path" nameconflict="makeunique">
    </cfif>
    <!-- InstanceBegin template="/Templates/maintemplate.dwt" codeOutsideHTMLIsLocked="false" -->
    <!-- DW6 -->
    <head>
    <!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>Insert New Photo</title>
    <!-- InstanceEndEditable -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="assets/intheworks.css" type="text/css" />
    <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
    </head>

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr bgcolor="02021e">
    <td colspan="4" rowspan="2" nowrap="nowrap" bgcolor="#02021E"><img src="../assets/intheworks_pg_ban.jpg" alt="Header image" width="400" height="140" border="0" /></td>
    <td height="58" colspan="4" valign="bottom" nowrap="nowrap" bgcolor="#02021E" id="logo">In The Works Photo Co.</td>
    </tr>
    <tr bgcolor="02021E">
    <td height="57" colspan="4" valign="top" nowrap="nowrap" bgcolor="#02021E" id="tagline">Photos By Independent Photographer Jermey Wilson</td>
    </tr>
    <tr>
    <td colspan="8" bgcolor="#cc3300"><img src="assets/intheworks_spacer.gif" alt="" width="1" height="2" border="0" /></td>
    </tr>

    <tr>
    <td colspan="8"><img src="assets/intheworks_spacer.gif" alt="" width="1" height="2" border="0" /></td>
    </tr>

    <tr>
    <td colspan="8" bgcolor="#cc3300"><img src="assets/intheworks_spacer.gif" alt="" width="1" height="1" border="0" /></td>
    </tr>

    <tr>
    <td colspan="8">&nbsp;&nbsp;<br /> </td>
    </tr>
    <tr>
    <td width="160" valign="top" height="370">
    <table border="0" cellspacing="0" cellpadding="0" width="155" id="navigation">
    <tr>
    <td width="155" height="40"><a href="index.html">Home</a></td>
    </tr>
    <tr>
    <td width="155" height="40"><a href="photogallery/index.cfm">photo gallery</a></td>
    </tr>
    <tr>
    <td width="155" height="40"><a href="aboutme/index.html">about me</a></td>
    </tr>
    <tr>
    <td width="155" height="40"><a href="contactme/index.html">contact me</a></td>
    </tr>
    <tr>
    <td height="40"><a href="login/index.cfm">login</a></td>
    </tr>
    </table>
    <br /></td>
    <td width="2" rowspan="2" bgcolor="#445DA0"><img src="assets/intheworks_spacer.gif" alt="" width="1" height="1" border="0" /></td>
    <th height="370" colspan="5" align="left" valign="top"><!-- InstanceBeginEditable name="Page Content" -->
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td height="40" class="pageName">Insert New Photo</td>
    </tr>
    </table>
    <br />
    <table width="600" border="0" align="center" cellpadding="0" cellspacing="0" class="subHeader">
    <tr>
    <td height="35" class="subHeader">Content Title Here</td>
    </tr>
    </table>
    <table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td><cfform action="index.cfm" method="post" enctype="multipart/form-data" name="upload_form" id="upload_form">
    <cfinput type="file" name="ul_path" id="ul_path">
    <cfinput type="submit" name="upload_now" id="upload_now" value="Upload">
    </cfform>
    </td>
    </tr>
    </table>
    <!-- InstanceEndEditable --></th>
    <td width="207" valign="top"><table width="200" border="0" align="right" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="3" id="sidebarHeader" class="sidebarHeader" align="center"><!-- InstanceBeginEditable name="Sidebar Heading" -->Side notes and/or latest info<!-- InstanceEndEditable --></td>
    </tr>
    <tr>
    <td width="45"><img src="assets/intheworks_spacer.gif" alt="" width="40" height="1" border="0" /></td>
    <td width="110" id="sidebar" class="smallText"><!-- InstanceBeginEditable name="Sidebar Content" -->
    <p><img src="" alt="Picture place holder" name="picture" width="110" height="110" id="picture" style="background-color: #99CCFF" /><br />
    Discription<br />
    <a href="javascript:;">read more &gt;</a></p>
    <p><img src="" alt="Picture place holder" name="picture" width="110" height="110" id="picture2" style="background-color: #99CCFF" /><br />
    Discription<br />
    <a href="javascript:;">read more &gt;</a></p>
    <p>&nbsp;</p>
    <!-- InstanceEndEditable --></td>
    <td width="45">&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td id="sidebar2" class="smallText">&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td width="160"><p><br />
    </p></td>
    <td width="152">&nbsp;</td>
    <td width="87">&nbsp;</td>
    <td width="413">&nbsp;</td>
    <td width="48">&nbsp;</td>
    <td width="196">&nbsp;</td>
    <td width="207">&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td bgcolor="#445DA0">&nbsp;</td>
    <td height="10" colspan="5" align="center">This site designed &amp; maintained by <a href="mailto:jstickel56@gmail.com">Joseph Stickel</a></td>
    <td>&nbsp;</td>
    </tr>
    </table>
    <!-- InstanceEnd --></body></html>
     
    cumupkid, Jan 23, 2008 IP
  3. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you are using IE it may be an issue with its weird mime types.
    http://rip747.wordpress.com/2007/05/09/cffile-upload-gotcha-with-ie-and-jpg/

    After you use cffile upload, you have access to a bunch of file variables, like CFFILE.serverFile (Filename of the file saved on the server). You can use those values in a cfquery to save the image name to your database table.

    
    Psuedo code
    <cfquery name="addImage" datasource="yourDSN">
        INSERT INTO YourTable ( ServerImageName, ... other columns )
        VALUES (  
             <cfqueryparam value="#CFFILE.serverFile#" cfsqltype="cf_sql_varchar">,
             .... other values ...
        )
    </cfquery>
    
    Code (markup):
    See here for more information on cffile upload variables
    http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p35.htm#wp3540091
     
    cfStarlight, Jan 23, 2008 IP
  4. cumupkid

    cumupkid Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks got that figured out, but still just dont get the second part. I added updated code.

    Thanks again for your help.

    <cfquery name="rsPhoto" datasource="intheworksphotoco">
    SELECT *
    FROM photos
    </cfquery>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <link href="../assets/intheworks.css" rel="stylesheet" type="text/css" />
    <body>
    <cfif isdefined ("form.upload_now")>

    <cffile accept="image/gif,image/jpg,image/jpeg,image/pjpeg"
    action="upload" destination="C:\ColdFusion8\wwwroot\intheworksphotoco\images\"
    filefield="ul_path"
    nameconflict="makeunique">
    </cfif>
    <!-- InstanceBegin template="/Templates/maintemplate.dwt" codeOutsideHTMLIsLocked="false" -->
    <!-- DW6 -->
    <head>
    <!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>Insert New Photo</title>
    <!-- InstanceEndEditable -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="assets/intheworks.css" type="text/css" />
    <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
    </head>

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr bgcolor="02021e">
    <td colspan="4" rowspan="2" nowrap="nowrap" bgcolor="#02021E"><img src="../assets/intheworks_pg_ban.jpg" alt="Header image" width="400" height="140" border="0" /></td>
    <td height="58" colspan="4" valign="bottom" nowrap="nowrap" bgcolor="#02021E" id="logo">In The Works Photo Co.</td>
    </tr>
    <tr bgcolor="02021E">
    <td height="57" colspan="4" valign="top" nowrap="nowrap" bgcolor="#02021E" id="tagline">Photos By Independent Photographer Jermey Wilson</td>
    </tr>
    <tr>
    <td colspan="8" bgcolor="#cc3300"><img src="assets/intheworks_spacer.gif" alt="" width="1" height="2" border="0" /></td>
    </tr>

    <tr>
    <td colspan="8"><img src="assets/intheworks_spacer.gif" alt="" width="1" height="2" border="0" /></td>
    </tr>

    <tr>
    <td colspan="8" bgcolor="#cc3300"><img src="assets/intheworks_spacer.gif" alt="" width="1" height="1" border="0" /></td>
    </tr>

    <tr>
    <td colspan="8">&nbsp;&nbsp;<br /> </td>
    </tr>
    <tr>
    <td width="160" valign="top" height="370">
    <table border="0" cellspacing="0" cellpadding="0" width="155" id="navigation">
    <tr>
    <td width="155" height="40"><a href="index.html">Home</a></td>
    </tr>
    <tr>
    <td width="155" height="40"><a href="photogallery/index.cfm">photo gallery</a></td>
    </tr>
    <tr>
    <td width="155" height="40"><a href="aboutme/index.html">about me</a></td>
    </tr>
    <tr>
    <td width="155" height="40"><a href="contactme/index.html">contact me</a></td>
    </tr>
    <tr>
    <td height="40"><a href="login/index.cfm">login</a></td>
    </tr>
    </table>
    <br /></td>
    <td width="2" rowspan="2" bgcolor="#445DA0"><img src="assets/intheworks_spacer.gif" alt="" width="1" height="1" border="0" /></td>
    <th height="370" colspan="5" align="left" valign="top"><!-- InstanceBeginEditable name="Page Content" -->
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td height="40" class="pageName">Insert New Photo</td>
    </tr>
    </table>
    <br />
    <table width="600" border="0" align="center" cellpadding="0" cellspacing="0" class="subHeader">
    <tr>
    <td height="35" class="subHeader">Content Title Here</td>
    </tr>
    </table>
    <table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td height="40"><cfform action="index.cfm" method="post" enctype="multipart/form-data" name="upload_form" id="upload_form">
    <table width="600" border="0">
    <tr>
    <td width="150" height="40">Photo Name:</td>
    <td width="450" height="40"><cfinput type="text" name="photoname" required="yes" id="photoname" size="40" maxlength="50"></td>
    </tr>
    <tr>
    <td width="150" height="40">Phot File Name:</td>
    <td width="450" height="40"><cfinput type="text" name="largeimage" required="yes" id="largeimage" size="40" maxlength="50"></td>
    </tr>
    <tr>
    <td width="150" height="40"> Photo Discription:</td>
    <td width="450" height="40"><cfinput type="text" name="discription" required="yes" id="discription" size="60" maxlength="200"></td>
    </tr>
    </table>
    <table width="600" border="0">
    <tr>
    <td height="40" colspan="2" align="center"><cfinput type="file" name="ul_path" required="yes" id="ul_path" size="30" maxlength="100"></td>
    </tr>
    <tr>
    <td width="300" height="40" align="right"><cfinput type="submit" name="upload_now" id="upload_now" value="Upload " size="15"></td>
    <td width="300" height="40" align="left"><cfinput type="reset" name="Reset" id="Reset" value="Reset" size="15"></td>
    </tr>
    </table>
    </cfform> </td>
    </tr>
    </table>
    <!-- InstanceEndEditable --></th>
    <td width="207" valign="top"><table width="200" border="0" align="right" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="3" id="sidebarHeader" class="sidebarHeader" align="center"><!-- InstanceBeginEditable name="Sidebar Heading" -->Side notes and/or latest info<!-- InstanceEndEditable --></td>
    </tr>
    <tr>
    <td width="45"><img src="assets/intheworks_spacer.gif" alt="" width="40" height="1" border="0" /></td>
    <td width="110" id="sidebar" class="smallText"><!-- InstanceBeginEditable name="Sidebar Content" -->
    <p><img src="" alt="Picture place holder" name="picture" width="110" height="110" id="picture" style="background-color: #99CCFF" /><br />
    Discription<br />
    <a href="javascript:;">read more &gt;</a></p>
    <p><img src="" alt="Picture place holder" name="picture" width="110" height="110" id="picture2" style="background-color: #99CCFF" /><br />
    Discription<br />
    <a href="javascript:;">read more &gt;</a></p>
    <p>&nbsp;</p>
    <!-- InstanceEndEditable --></td>
    <td width="45">&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td id="sidebar2" class="smallText">&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td width="160"><p><br />
    </p></td>
    <td width="152">&nbsp;</td>
    <td width="87">&nbsp;</td>
    <td width="413">&nbsp;</td>
    <td width="48">&nbsp;</td>
    <td width="196">&nbsp;</td>
    <td width="207">&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td bgcolor="#445DA0">&nbsp;</td>
    <td height="10" colspan="5" align="center">This site designed &amp; maintained by <a href="mailto:jstickel56@gmail.com">Joseph Stickel</a></td>
    <td>&nbsp;</td>
    </tr>
    </table>
    <!-- InstanceEnd --></body></html>
     
    cumupkid, Jan 23, 2008 IP
  5. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Inside the section above is where you will add the code to insert the image info into your database.

    You can retrieve the name of the file that was uploaded by using the CFFILE variables. Use the file name value in a query to add the information to your database. Does that make sense?

    Not tested, but something like this. Note, I do not know the names of your table columns so I have used placeholders.

    
    <cfif isdefined ("form.upload_now")>
    <cffile accept="image/gif,image/jpg,image/jpeg,image/pjpeg"
         action="upload"      
         destination="C:\ColdFusion8\wwwroot\intheworksphotoco\images\"
         filefield="ul_path"
         nameconflict="makeunique">
    
    <!--- use cfqueryparam instead --->
    <cfquery name="addImage" datasource="intheworksphotoco">
        INSERT INTO photos ( TheImageNameColumn )
        VALUES ( '#CFFILE.serverFile#' )
    </cfquery>
    </cfif>
    
    Code (markup):
     
    cfStarlight, Jan 23, 2008 IP
  6. cumupkid

    cumupkid Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Ive tried over n over but cant understand...

    I have photoid, largeimage, discription, photoname as my tables in my database intheworksphotoco

    Any more help?

    Thanks.
     
    cumupkid, Jan 24, 2008 IP
  7. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Here is what I understand from your description. I think you want to insert these form fields into your table.

    
    <cfinput type="text" name="photoname" required="yes" id="photoname" size="40" maxlength="50">
    <cfinput type="text" name="largeimage" required="yes" id="largeimage" size="40" maxlength="50">
    <cfinput type="text" name="discription" required="yes" id="discription" size="60" maxlength="200">
    <cfinput type="file" name="ul_path" required="yes" id="ul_path" size="30" maxlength="100">
    
    Code (markup):
    When you submit a form using "post", you can get the values of the form fields using the syntax #FORM.theNameOfTheField#. (You always use the keyword FORM, not the name of your form.). In your case

    
    #FORM.photoName#, #FORM.largeimage#, ... other form field names ...
    
    Code (markup):
    I am assuming "photoid" is some sort of auto-incrementing column. Meaning you do not need to include that column it in your insert query, because your database will automatically generate an ID whenever you add a new record to the table.

    So based on what you've said, your insert statement might look something like the query below. I cannot give you the exact syntax because I do not know the data types of your columns or what database you are using.

    <cfquery name="addImage" datasource="intheworksphotoco">
    INSERT INTO photos (largeimage, discription, photoname)
    VALUES ( '#FORM.largeimage#', '#FORM.discription#', '#FORM.photoname#' )
    </cfquery>

    BUT ... you seem to be missing a column. Where are you storing the name of the uploaded file?
     
    cfStarlight, Jan 24, 2008 IP
  8. cumupkid

    cumupkid Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I can get the file to upload to the correct place, OR i can get the information to go to the database, ... can not get them both to work at the same time.

    More code below

    I think that the code ive highlighted in red is where im having my problem?


    <cfif IsDefined("FORM.upload_now")>
    <cffile accept="image/gifimage/jpg,image/jpeg,image/pjpeg" action="upload" destination="C:\ColdFusion8\wwwroot\intheworksphotoco\images\" filefield="ul_path" nameconflict="error">
    <cfelse>
    </cfif>




    <cfset CurrentPage=GetFileFromPath(GetBaseTemplatePath())>
    <cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "form1">
    <cfquery datasource="intheworksphotoco">
    INSERT INTO photos (PHOTONAME, LARGEIMAGE, DISCRIPTION)
    VALUES (<cfif IsDefined("FORM.photoname") AND #FORM.photoname# NEQ "">
    <cfqueryparam value="#FORM.photoname#" cfsqltype="cf_sql_clob" maxlength="50">
    <cfelse>
    ''
    </cfif>
    , <cfif IsDefined("FORM.largeimage") AND #FORM.largeimage# NEQ "">
    <cfqueryparam value="#FORM.largeimage#" cfsqltype="cf_sql_clob" maxlength="30">
    <cfelse>
    ''
    </cfif>
    , <cfif IsDefined("FORM.discription") AND #FORM.discription# NEQ "">
    <cfqueryparam value="#FORM.discription#" cfsqltype="cf_sql_clob" maxlength="2147483647">
    <cfelse>
    ''
    </cfif>)
    </cfquery>
    </cfif>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <!-- DW6 -->
    <head>
    <!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->

    <title>Upload Photo</title>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="../assets/intheworks.css" type="text/css" />
    </head>
    <body>

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr bgcolor="02021e">
    <td colspan="4" rowspan="2" nowrap="nowrap" bgcolor="#02021E"><img src="../assets/intheworks_pg_ban.jpg" alt="Header image" width="400" height="140" border="0" /></td>
    <td height="58" colspan="4" valign="bottom" nowrap="nowrap" bgcolor="#02021E" id="logo">In The Works Photo Co.</td>
    </tr>
    <tr bgcolor="02021E">
    <td height="57" colspan="4" valign="top" nowrap="nowrap" bgcolor="#02021E" id="tagline">Photos By Independent Photographer Jermey Wilson</td>
    </tr>
    <tr>
    <td colspan="8" bgcolor="#cc3300"><img src="../assets/intheworks_spacer.gif" alt="" width="1" height="2" border="0" /></td>
    </tr>

    <tr>
    <td colspan="8"><img src="../assets/intheworks_spacer.gif" alt="" width="1" height="2" border="0" /></td>
    </tr>

    <tr>
    <td colspan="8" bgcolor="#cc3300"><img src="../assets/intheworks_spacer.gif" alt="" width="1" height="1" border="0" /></td>
    </tr>

    <tr>
    <td colspan="8">&nbsp;&nbsp;<br /> </td>
    </tr>
    <tr>
    <td width="160" valign="top" height="370">
    <table border="0" cellspacing="0" cellpadding="0" width="155" id="navigation">
    <tr>
    <td width="155" height="40"><a href="../index.html">Home</a></td>
    </tr>
    <tr>
    <td width="155" height="40"><a href="../photogallery/index.cfm">photo gallery</a></td>
    </tr>
    <tr>
    <td width="155" height="40"><a href="../aboutme/index.html">about me</a></td>
    </tr>
    <tr>
    <td width="155" height="40"><a href="../contactme/index.html">contact me</a></td>
    </tr>
    <tr>
    <td height="40"><a href="../login/index.cfm">login</a></td>
    </tr>
    </table>
    <br /></td>
    <td width="2" rowspan="2" bgcolor="#445DA0"><img src="../assets/intheworks_spacer.gif" alt="" width="1" height="1" border="0" /></td>
    <th height="370" colspan="5" align="left" valign="top">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td height="40" class="pageName">Upload Photos</td>
    </tr>
    </table>
    <br />
    <table width="600" border="0" align="center" cellpadding="0" cellspacing="0" class="subHeader">
    <tr>
    <td height="35" class="subHeader">Photo Information</td>
    </tr>
    </table> <table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td><form action="<cfoutput>#CurrentPage#</cfoutput>" method="POST" enctype="multipart/form-data" name="upload_form" id="upload_form">
    <table width="600" border="0">
    <tr>
    <td width="150" height="40">Photo Name:</td>
    <td width="450" height="40"><input type="text" name="photoname" id="photoname" /></td>
    </tr>
    <tr>
    <td width="150" height="40">Phot File Name:</td>
    <td width="450" height="40"><input type="text" name="largeimage" id="largeimage" /></td>
    </tr>
    <tr>
    <td width="150" height="40"> Photo Discription:</td>
    <td width="450" height="40"><input type="text" name="discription" id="discription" /></td>
    </tr>
    <tr>
    <td height="40" colspan="2" align="center"><input type="file" name="ul_path" id="ul_path" /></td>
    </tr>
    <tr>
    <td height="40">&nbsp;</td>
    <td height="40"><input type="submit" name="submit" id="submit" value="Upload" /></td>
    </tr>
    </table>
    <input type="hidden" name="MM_InsertRecord" value="form1" />
    </form> </td>
    </tr>
    </table></th>
    <td width="207" valign="top"><table width="200" border="0" align="right" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="3" id="sidebarHeader" class="sidebarHeader" align="center">Side notes and/or latest info</td>
    </tr>
    <tr>
    <td width="45"><img src="../assets/intheworks_spacer.gif" alt="" width="40" height="1" border="0" /></td>
    <td width="110" id="sidebar" class="smallText">
    <p><img src="" alt="Picture place holder" name="picture" width="110" height="110" id="picture" style="background-color: #99CCFF" /><br />
    Discription<br />
    <a href="javascript:;">read more &gt;</a></p>
    <p><img src="" alt="Picture place holder" name="picture" width="110" height="110" id="picture2" style="background-color: #99CCFF" /><br />
    Discription<br />
    <a href="javascript:;">read more &gt;</a></p> <p>&nbsp;</p></td>
    <td width="45">&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td id="sidebar2" class="smallText">&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td width="160"><p><br />
    </p></td>
    <td width="152">&nbsp;</td>
    <td width="87">&nbsp;</td>
    <td width="413">&nbsp;</td>
    <td width="48">&nbsp;</td>
    <td width="196">&nbsp;</td>
    <td width="207">&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td bgcolor="#445DA0">&nbsp;</td>
    <td height="10" colspan="5" align="center">This site designed &amp; maintained by <a href="mailto:jstickel56@gmail.com">Joseph Stickel</a></td>
    <td>&nbsp;</td>
    </tr>
    </table>
    </body>
    </html>
     
    cumupkid, Jan 24, 2008 IP
  9. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9


    Its a lot of code to sift through. But I do not see a field named FORM.upload_now anywhere.

    Right now you have two separate cfif statements that are checking different things. So it is not surprising that the code is not running both actions at the same time.

    What you should be doing is 1) determine if the form was submitted. 2) Inside that same check, upload the file AND insert the record into the db.

    
    <cfif ... the form was submitted ...>
         <cffile ... do the upload>
         <cfquery >
               do the query here
         </cfquery>
    </cfif>
    
    Code (markup):
     
    cfStarlight, Jan 24, 2008 IP
  10. cumupkid

    cumupkid Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Getting closer.

    form will now upload photo but not add info to mysql.
    What you were saying is what i want but didnt understand...

    I have posetd the error message and highlighted in red the supposed error.


    Error Executing Database Query.
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 13


    Resources:
    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.
    Check the ColdFusion documentation to verify that you are using the correct syntax.
    Search the Knowledge Base to find a solution to your problem.


    Browser Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)
    Remote Address 127.0.0.1
    Referrer http://localhost:8500/intheworksphotoco/admin/insertphoto_to_combo.cfm
    Date/Time 27-Jan-08 11:59 AM







    <cflock scope="Session" type="ReadOnly" timeout="30" throwontimeout="no">
    <cfset MM_Username=Iif(IsDefined("Session.MM_Username"),"Session.MM_Username",DE(""))>
    <cfset MM_UserAuthorization=Iif(IsDefined("Session.MM_UserAuthorization"),"Session.MM_UserAuthorization",DE(""))>
    </cflock>
    <cfif MM_Username EQ "">
    <cfset MM_referer=CGI.SCRIPT_NAME>
    <cfif CGI.QUERY_STRING NEQ "">
    <cfset MM_referer=MM_referer & "?" & CGI.QUERY_STRING>
    </cfif>
    <cfset MM_failureURL="login.cfm?accessdenied=" & URLEncodedFormat(MM_referer)>
    <cflocation url="#MM_failureURL#" addtoken="no">
    </cfif>
    <cfset CurrentPage=GetFileFromPath(GetBaseTemplatePath())>
    <cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "upload_to_mysql">
    <cfquery datasource="intheworksphotoco">
    INSERT INTO photos (PHOTONAME, LARGEIMAGE, DISCRIPTION)
    VALUES (<cfif IsDefined("FORM.photoname") AND #FORM.photoname# NEQ "">
    <cfqueryparam value="#FORM.photoname#" cfsqltype="cf_sql_clob" maxlength="50">
    <cfelse>
    ''
    </cfif>
    , <cfif IsDefined("FORM.largeimage") AND #FORM.largeimage# NEQ "">
    <cfqueryparam value="#FORM.largeimage#" cfsqltype="cf_sql_clob" maxlength="30">
    <cfelse>
    ''
    </cfif>
    , <cfif IsDefined("FORM.discription") AND #FORM.discription# NEQ "">
    <cfqueryparam value="#FORM.discription#" cfsqltype="cf_sql_clob" maxlength="2147483647">
    <cfelse>
    ''

    </cfif>
    , <cfif IsDefined("FORM.submit")><cffile accept="image/jpg,image/jpeg,image/pjpeg" action="upload" destination="C:\ColdFusion8\wwwroot\intheworksphotoco\images\" filefield="ul_path" nameconflict="error">
    <cfelse>
    ''


    </cfif>
    )
    </cfquery>
    <cflocation url="masterphoto_list.cfm">
    </cfif>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <!-- DW6 -->
    <head>
    <!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->

    <title>Upload Photo Info</title>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="../assets/intheworks.css" type="text/css" />
    </head>
    <body>

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr bgcolor="02021e">
    <td colspan="4" rowspan="2" nowrap="nowrap" bgcolor="#02021E"><img src="../assets/intheworks_pg_ban.jpg" alt="Header image" width="400" height="140" border="0" /></td>
    <td height="58" colspan="4" valign="bottom" nowrap="nowrap" bgcolor="#02021E" id="logo">In The Works Photo Co.</td>
    </tr>
    <tr bgcolor="02021E">
    <td height="57" colspan="4" valign="top" nowrap="nowrap" bgcolor="#02021E" id="tagline">Photos By Independent Photographer Jermey Wilson</td>
    </tr>
    <tr>
    <td colspan="8" bgcolor="#cc3300"><img src="../assets/intheworks_spacer.gif" alt="" width="1" height="2" border="0" /></td>
    </tr>

    <tr>
    <td colspan="8"><img src="../assets/intheworks_spacer.gif" alt="" width="1" height="2" border="0" /></td>
    </tr>

    <tr>
    <td colspan="8" bgcolor="#cc3300"><img src="../assets/intheworks_spacer.gif" alt="" width="1" height="1" border="0" /></td>
    </tr>

    <tr>
    <td colspan="8">&nbsp;&nbsp;<br /> </td>
    </tr>
    <tr>
    <td width="160" valign="top" height="370"><table border="0" cellspacing="0" cellpadding="0" width="155" id="navigation">
    <tr>
    <td width="155" height="40"><a href="../index.html">Home</a></td>
    </tr>
    <tr>
    <td width="155" height="40"><a href="../photogallery/index.cfm">photo gallery</a></td>
    </tr>
    <tr>
    <td width="155" height="40"><a href="../aboutme/index.html">about me</a></td>
    </tr>
    <tr>
    <td width="155" height="40"><a href="../contactme/index.html">contact me</a></td>
    </tr>
    </table>
    <br /></td>
    <td width="2" rowspan="2" bgcolor="#445DA0"><img src="../assets/intheworks_spacer.gif" alt="" width="1" height="1" border="0" /></td>
    <th height="370" colspan="5" align="left" valign="top">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td height="40" class="pageName">Upload Photo Information</td>
    </tr>
    </table>
    <br />
    <table width="600" border="0" align="center" cellpadding="0" cellspacing="0" class="subHeader">
    <tr>
    <td height="40" class="subHeader">Photo Information</td>
    </tr>
    </table> <table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td><form action="<cfoutput>#CurrentPage#</cfoutput>" method="POST" enctype="multipart/form-data" name="upload_to_mysql" id="upload_to_mysql">
    <table width="600" border="0">
    <tr>
    <td width="150" height="40">Photo Name:</td>
    <td width="450" height="40"><input type="text" name="photoname" id="photoname" /></td>
    </tr>
    <tr>
    <td width="150" height="40">Phot File Name:</td>
    <td width="450" height="40"><input type="text" name="largeimage" id="largeimage" /></td>
    </tr>
    <tr>
    <td width="150" height="40"> Photo Discription:</td>
    <td width="450" height="40"><input type="text" name="discription" id="discription" /></td>
    </tr>
    <tr>
    <td height="40" align="center">&nbsp;</td>
    <td height="40" align="left"><input name="ul_path" type="file" id="ul_path" size="20" /></td>
    </tr>
    <tr>
    <td height="40">&nbsp;</td>
    <td height="40"><input type="submit" name="submit" id="submit" value="Upload" />
    <input type="reset" name="reset" id="reset" value="Reset" /></td>
    </tr>
    </table>
    <input type="hidden" name="MM_InsertRecord" value="upload_to_mysql" />
    </form> </td>
    </tr>
    </table></th>
    <td width="207" valign="top"><table width="155" border="0" align="right" cellpadding="0" cellspacing="0" id="navigation2">
    <tr>
    <td width="155" height="40" align="right"><a href="index.cfm">Admin Home</a></td>
    </tr>
    <tr>
    <td width="155" height="40" align="right"><a href="masterphoto_list.cfm"> Photo Info List</a></td>
    </tr>
    <tr>
    <td width="155" height="40" align="right"><a href="insertphoto_to_file.cfm">Upload Photo</a></td>
    </tr>
    <tr>
    <td height="40" align="right"><a href="insertphoto_to_mysql.cfm">Insert Photo Info</a></td>
    </tr>
    <tr>
    <td height="40" align="right"><a href="logout.cfm">logout</a></td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td width="160"><p><br />
    </p></td>
    <td width="152">&nbsp;</td>
    <td width="87">&nbsp;</td>
    <td width="413">&nbsp;</td>
    <td width="48">&nbsp;</td>
    <td width="196">&nbsp;</td>
    <td width="207">&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td bgcolor="#445DA0">&nbsp;</td>
    <td height="10" colspan="5" align="center">This site designed &amp; maintained by <a href="mailto:jstickel56@gmail.com">Joseph Stickel</a></td>
    <td>&nbsp;</td>
    </tr>
    </table>
    </body>
    </html>
     
    cumupkid, Jan 27, 2008 IP
  11. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    That type of logic really belongs in an Application.cfc or Application.cfm file. Not on an upload page. But that is another question.

    I doubt you can do an upload in the middle of a cfquery, or if you can you shouldn't.

    I know you're just getting started with this, but if at all possible do not use the automated Dreamweaver code. It is just bad code and very difficult to read. Nothing to do with you, its just a fault of Dreamweaver IMO :)

    Start with the basic code like below. (Not tested). Also two important questions
    1) Where are you storing the name of the uploaded file? I do not see a column in your table for that.
    2) I doubt you really want a description field that long. That is a very large field.

    
    <cfset CurrentPage = GetFileFromPath(GetBaseTemplatePath())>
    
    If this field is defined, it means the form was submitted ..<br>
    <cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "upload_to_mysql">
    	Step 1:  Upload the file<br>
    	<cffile accept="image/jpg,image/jpeg,image/pjpeg" action="upload" destination="C:\ColdFusion8\wwwroot\intheworksphotoco\images\" filefield="ul_path" nameconflict="error">
    
    	Step 2:  Insert the information into your database.  
    	NOTE. Where are you putting the name of the uploaded file? 
    	 
    	<cfquery datasource="intheworksphotoco">
    		INSERT INTO photos (PHOTONAME, LARGEIMAGE, DISCRIPTION)
    		VALUES 
    		(
    		<cfqueryparam value="#FORM.photoname#" cfsqltype="cf_sql_varchar" maxlength="50">,
    		<cfqueryparam value="#FORM.largeimage#" cfsqltype="cf_sql_varchar" maxlength="30">,
    		[COLOR="Blue"]<!--- do you really need a description field this long? --->[/COLOR]
    		<cfqueryparam value="#FORM.discription#" cfsqltype="cf_sql_clob" maxlength="[COLOR="Red"][B]2147483647[/B][/COLOR]">
    		)
    	</cfquery>
    	<cflocation url="masterphoto_list.cfm">
    </cfif>
    
    <cfoutput>
    <form action="#CurrentPage#" method="POST" enctype="multipart/form-data" name="upload_to_mysql" id="upload_to_mysql">
    </cfoutput>
    <table width="600" border="0">
    <tr>
    <td width="150" height="40">Photo Name:</td>
    <td width="450" height="40"><input type="text" name="photoname" id="photoname" /></td>
    </tr>
    <tr>
    <td width="150" height="40">Phot File Name:</td>
    <td width="450" height="40"><input type="text" name="largeimage" id="largeimage" /></td>
    </tr>
    <tr>
    <td width="150" height="40"> Photo Discription:</td>
    <td width="450" height="40"><input type="text" name="discription" id="discription" /></td>
    </tr>
    <tr>
    <td height="40" align="center">&nbsp;</td>
    <td height="40" align="left"><input name="ul_path" type="file" id="ul_path" size="20" /></td>
    </tr>
    <tr>
    <td height="40">&nbsp;</td>
    <td height="40"><input type="submit" name="submit" id="submit" value="Upload" />
    <input type="reset" name="reset" id="reset" value="Reset" /></td>
    </tr>
    </table>
    <input type="hidden" name="MM_InsertRecord" value="upload_to_mysql" />
    </form> 
    
    Code (markup):
     
    cfStarlight, Jan 27, 2008 IP
  12. cumupkid

    cumupkid Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I beleive Photo File Name points to Largeimage in mysql that is what refrences the actual image file name. I was wanting to make it to where i wouldnt need to enter the name, and it would pull it from the file search field.

    Thanks fpor understanding that im new to this..
     
    cumupkid, Jan 27, 2008 IP
  13. cumupkid

    cumupkid Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Thanks alot

    works like a charm.

    Any advice on that thing where I can get the file name to auto populate the PHOTO FIL NAME wich points to LARGEFILE in my database and that column points to the file in my root where pictures are stored.

    Also I was trying to learn how to build a flash slide show that will automatically scroll through my database bictures.

    THANKS AGAIN for the help....
     
    cumupkid, Jan 27, 2008 IP
  14. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Directly after you upload a file with CFFILE

    
    <cffile action="upload" ...>
    
    Code (markup):
    ColdFusion gives you access to a bunch of variables that contain information about the form. Its only available right after you use <cffile action="upload" >. One of those variables is CFFILE.ServerFile. It is the name of the file that was saved to the server. It does not include the path. You can read about all of the cffile variables here
    http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p35.htm#wp3540091

    To insert the name of the saved file, instead of the form field, replace

    
    <cfqueryparam value="#FORM.largeimage#" cfsqltype="cf_sql_varchar" maxlength="30">
    
    Code (markup):
    with

    
    <cfqueryparam value="#CFFILE.ServerFile#" cfsqltype="cf_sql_varchar" maxlength="30">
    
    Code (markup):
    My flash skills are rusty, so I will let someone else answer that question.
     
    cfStarlight, Jan 27, 2008 IP
  15. cumupkid

    cumupkid Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Thanks alot
    everything works great


    I know this may be very simple but... Point me in the right direction for making a search app that searches the database.... for something like name of event or picture.

    Also I want to make it possible for people do download a fullsize image, or prevent them from downloading without being aloud to?

    thanks again for the help so far.
     
    cumupkid, Jan 28, 2008 IP
  16. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Check over at easycfm.com. They have some tutorials on creating search pages and login examples

    http://tutorial200.easycfm.com/
    http://tutorial8.easycfm.com/

    Read up on cfcontent. Images and other non cf files can typically be accessed by anyone that has the direct url. cfcontent can be used to serve up files that reside outside a web accessible directory. Used in conjunction with a login system and your Application.cfc file you can restrict access to those files.
     
    cfStarlight, Feb 1, 2008 IP