Forums

This topic is locked

Update image field return a null value

Posted 12 Jul 2003 20:43:54
1
has voted
12 Jul 2003 20:43:54 Ric A posted:
I have a problem when I try to update image.
If I select an image on the update page it works fine but if
I don't select any image the other fields will be update
correctly but the image field return with a null
value in the database.
There is possible if I don't select any image that
select the recordset it contains the image value and
insert it in the same image field?

I use Pure ASP UPLOAD 2.13 and Update command (Stored Procedure).
A page send value to update page called (update.asp)

Here is the code for update.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/tdsfconn.asp" -->
<!--#include file="ScriptLibrary/incPureUpload.asp" -->
<%
'*** Pure ASP File Upload 2.1.3
Dim GP_uploadAction,UploadQueryString
PureUploadSetup
If (CStr(Request.QueryString("GP_upload") <> "" Then
Dim pau_thePath,pau_Extensions,pau_Form,pau_Redirect,pau_storeType,pau_sizeLimit,pau_nameConflict,pau_requireUpload,pau_minWidth,pau_minHeight,pau_maxWidth,pau_maxHeight,pau_saveWidth,pau_saveHeight,pau_timeout,pau_progressBar,pau_progressWidth,pau_progressHeight
pau_thePath = """imgs"""
pau_Extensions = ""
pau_Form = "form1"
pau_Redirect = ""
pau_storeType = "file"
pau_sizeLimit = ""
pau_nameConflict = "over"
pau_requireUpload = "false"
pau_minWidth = ""
pau_minHeight = ""
pau_maxWidth = ""
pau_maxHeight = ""
pau_saveWidth = ""
pau_saveHeight = ""
pau_timeout = "600"
pau_progressBar = "showProgress.htm"
pau_progressWidth = "300"
pau_progressHeight = "100"

Dim RequestBin, UploadRequest
CheckPureUploadVersion 2.13
ProcessUpload pau_thePath,pau_Extensions,pau_Redirect,pau_storeType,pau_sizeLimit,pau_nameConflict,pau_requireUpload,pau_minWidth,pau_minHeight,pau_maxWidth,pau_maxHeight,pau_saveWidth,pau_saveHeight,pau_timeout
end if
%>

<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
If (Request.QueryString("AlbumID" <> "" Then
Recordset1__MMColParam = Request.QueryString("AlbumID"
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset"
Recordset1.ActiveConnection = MM_tdsfconn_STRING
Recordset1.Source = "SELECT * FROM tot WHERE AlbumID = " + Replace(Recordset1__MMColParam, "'", "''" + ""
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<% If UploadFormRequest("update" <> "" Then %>

<% If UploadFormRequest("imgs2" <> "" Then %>

<% varimg2 = Recordset1.Fields.Item("imgs".Value %>

<%

if(UploadFormRequest("album" <> "" then Command2__varalb = UploadFormRequest("album"

if(UploadFormRequest("artist" <> "" then Command2__varart = UploadFormRequest("artist"

if(UploadFormRequest("format" <> "" then Command2__varform = UploadFormRequest("format"

if(UploadFormRequest("genre" <> "" then Command2__vargenre = UploadFormRequest("genre"

if(varimg2 <> "" then Command2__varimmagine = varimg2

if(UploadFormRequest("hdnID" <> "" then Command2__varID = UploadFormRequest("hdnID"

%>
<%

set Command2 = Server.CreateObject("ADODB.Command"
Command2.ActiveConnection = MM_tdsfconn_STRING
Command2.CommandText = "UPDATE tot SET AlbumTitle = '" + Replace(Command2__varalb, "'", "''" + "', ArtistName = '" + Replace(Command2__varart, "'", "''" + "', FormatID = '" + Replace(Command2__varform, "'", "''" + "', GenreID = '" + Replace(Command2__vargenre, "'", "''" + "', imgs = '" + Replace(Command2__varimmagine, "'", "''" + "' WHERE AlbumID = " + Replace(Command2__varID, "'", "''" + " "
Command2.CommandType = 1
Command2.CommandTimeout = 0
Command2.Prepared = true
Function newFileSystemObject()
set newFileSystemObject=Server.CreateObject("Scripting.FileSystemObject"
End Function
Function fileExists(aFileSpec)
fileExists=newFileSystemObject.fileExists(aFileSpec)
End Function
If UploadFormRequest("imgs"<> "" OR UploadFormRequest("delete_image" <> "" Then
' create file scripting object
Set File = CreateObject("Scripting.FileSystemObject"
FolderPath = Server.MapPath("imgs/"
ImagePath = FolderPath & "/" & (Recordset1.Fields.Item("imgs".Value)
' check if file exists and if true delete the file
If fileExists(ImagePath) Then
File.DeleteFile(ImagePath)
End If
End if
Command2.Execute()

%>

<% else %>

<%

if(UploadFormRequest("album" <> "" then Command1__varalb = UploadFormRequest("album"

if(UploadFormRequest("artist" <> "" then Command1__varart = UploadFormRequest("artist"

if(UploadFormRequest("format" <> "" then Command1__varform = UploadFormRequest("format"

if(UploadFormRequest("genre" <> "" then Command1__vargenre = UploadFormRequest("genre"

if(UploadFormRequest("imgs2" <> "" then Command1__varimg = UploadFormRequest("imgs2"

if(UploadFormRequest("hdnID" <> "" then Command1__varID = UploadFormRequest("hdnID"

%>
<%

set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_tdsfconn_STRING
Command1.CommandText = "UPDATE tot SET AlbumTitle = '" + Replace(Command1__varalb, "'", "''" + "', ArtistName = '" + Replace(Command1__varart, "'", "''" + "', FormatID = '" + Replace(Command1__varform, "'", "''" + "', GenreID = '" + Replace(Command1__vargenre, "'", "''" + "', imgs = '" + Replace(Command1__varimg, "'", "''" + "' WHERE AlbumID = " + Replace(Command1__varID, "'", "''" + " "
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Function newFileSystemObject()
set newFileSystemObject=Server.CreateObject("Scripting.FileSystemObject"
End Function
Function fileExists(aFileSpec)
fileExists=newFileSystemObject.fileExists(aFileSpec)
End Function
If UploadFormRequest("imgs"<> "" OR UploadFormRequest("delete_image" <> "" Then
' create file scripting object
Set File = CreateObject("Scripting.FileSystemObject"
FolderPath = Server.MapPath("imgs/"
ImagePath = FolderPath & "/" & (Recordset1.Fields.Item("imgs".Value)
' check if file exists and if true delete the file
If fileExists(ImagePath) Then
File.DeleteFile(ImagePath)
End If
End if
Command1.Execute()

%>
<% End If %>

<% End If %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" src="ScriptLibrary/incPureUpload.js"></script>
</head>

<body>
<form action="<%=GP_uploadAction%>" method="post" enctype="multipart/form-data" name="form1" onSubmit="checkFileUpload(this,'',false,'','','','','','','');showProgressWindow('showProgress.htm',300,100);return document.MM_returnValue">
<table width="350" border="1" align="center">
<tr>
<td width="92">AlbumID</td>
<td width="242">
<input name="hdnID" type="hidden" id="hdnID" value="<%=(Recordset1.Fields.Item("AlbumID".Value)%>"></td>
</tr>
<tr>
<td>Genre</td>
<td>
<input name="genre" type="text" id="genre" value="<%=(Recordset1.Fields.Item("GenreID".Value)%>"></td>
</tr>
<tr>
<td>Artist</td>
<td>
<input name="artist" type="text" id="artist" value="<%=(Recordset1.Fields.Item("ArtistName".Value)%>"></td>
</tr>
<tr>
<td>Album</td>
<td>
<input name="album" type="text" id="album" value="<%=(Recordset1.Fields.Item("AlbumTitle".Value)%>"></td>
</tr>
<tr>
<td>Format</td>
<td>
<input name="format" type="text" id="format" value="<%=(Recordset1.Fields.Item("FormatID".Value)%>"></td>
</tr>
<tr>
<td>imgs</td>
<td>
<%
If (Recordset1.Fields.Item("imgs".Value) <> "" Then
Response.Write("<tr><td nowrap class=""specialbold"">Immagine attuale</td><td><img src='"&("imgs/" & (Recordset1.Fields.Item("imgs".Value)&"'></td></tr><tr><td nowrap class=""specialbold"">Spunta per cancellare il file</td><td><input type=""checkbox"" name=""delete_image"" value=""checkbox""></td></tr>"
Else
Response.Write(""
End if
%>
</td>
</tr>
<tr>
<td>imgs2</td>
<td>
<input name="imgs2" type="file" id="imgs2" onChange="checkOneFileUpload(this,'',false,'','','','','','','')"></td>
</tr>
<tr>
<td> </td>
<td>
<input name="update" type="submit" id="update" value="update"></td>
</tr>
</table>
</form>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>


Anyone can help me?

Reply to this topic