lulu50
asked on
Add a description name to the database
Hi,
I have file upload text box and a text box for the description.
I am having a problem inserting File description to my database.
Is this correct -> value="#Descp[ii]#"
this is what I have
I have file upload text box and a text box for the description.
I am having a problem inserting File description to my database.
Is this correct -> value="#Descp[ii]#"
this is what I have
<cfoutput>
<cfloop from="1" to="3" index="ii"> <tr>
<td style="width:120px;">File Description</td>
<td rowspan="2" align="left" valign="top" style="padding-right:5px;">
<INPUT TYPE="input" NAME="FileDescription#ii#" id="FileDescription#ii#" style="width:400px;">
<INPUT TYPE="FILE" NAME="AttachFile#ii#" id="AttachFile#ii#" onchange="return validateFileExtension(this);" class="file" style="width:400px;">
<input type="button" value="Delete" name="DeleteFile#ii#" id="DeleteFile#ii#" style="height:20px;float:right;margin-right:87px;" onclick="clearFile('AttachFile' + #ii#,'FileDescription' + #ii# );" />
</tr>
<tr>
<td style="width:120px;"> </td>
</tr>
</cfloop>
</cfoutput>
<!--- Insert Uploaded files --->
<cfset filelocation = expandpath('uploadedfiles/')>
<cfset maxFiles = 3>
<cfset Attachments="">
<cfloop from="1" to="#variables.maxFiles#" index="ii">
<cftry>
<cfif StructKeyExists(form,"AttachFile" & ii) && len(trim(Form["AttachFile" & ii]))>
<cfset Descp[ii] = #Form["FileDescription" & ii]#>
<CFFILE ACTION="UPLOAD"
FILEFIELD="AttachFile#ii#"
DESTINATION="#variables.filelocation#"
NAMECONFLICT="makeunique">
<cfset Attachments=ListAppend(variables.Attachments,cffile.serverfile)>
</cfif>
<cfcatch>
<br>#cfcatch.message#<br>#cfcatch.detail#<br>
#cfcatch.tagContext[1].template# Line #cfcatch.tagContext[1].line#
</cfcatch></cftry>
</cfloop>
<cfif len(trim(variables.Attachments))>
<cfquery name = "QLogFiles" datasource="#strDSN#" username="#strUID#" password="#strPWD#">
Set Nocount On;
<cfloop list="#variables.Attachments#" index="ii">
<cfif FileExists(variables.filelocation & ii)>
INSERT INTO Files
(FileName,UploadedFile,IssueID,Status,CreatedDate)
VALUES
(
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Descp[ii]#">,
<cfqueryparam cfsqltype="cf_sql_blob"
value="#FileReadBinary(variables.filelocation & ii)#">,
#IssueIDVal#,
1,
<cfqueryparam cfsqltype="cf_sql_date" value="#Now()#" /> )
</cfif>
</cfloop>
</cfquery>
</cfif>
also check the dataType in the database make sure the description field in the database allows that many characters that you are trying to insert
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@dgrafx.
His code will work fine, only thing is it is not a best practice, the code you showed is a way good and very neat and clean.
His code will work fine, only thing is it is not a best practice, the code you showed is a way good and very neat and clean.
sorry to disagree but it absolutely is best practice!
good luck ...
good luck ...
ASKER
Thank you for your help!!!!
Here is the screenshot, but there are far better ways to do the same thing you did. If i get some time by evening, i will post the better way of handling this
regards
upload.png