ASP Gallery / Database problems ..
I am using the code below to allow me to upload 4 images simultaneously, and also write member information to a database. Problem is, the member information is added for each image that is uploaded. Each member will have 4 images, and I do not need the info to be entered 4 times. Is there a way I can have this information only enter once for each group of 4 member images uploaded?
Please help ..
'On Error Resume Next
<!-- #include file="Connections/datastore.asp" -->
<!-- METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
Set Upload = Server.CreateObject("Persits.Upload")
Set Jpeg = Server.CreateObject("Persits.Jpeg")
For Each File in Upload.Files
If File.ImageType <> "JPG" Then
Response.Write "This is not a JPEG image."
L = 75
Jpeg.Quality = 90
Jpeg.Interpolation = 1
Jpeg.Width = L
Jpeg.Height = Jpeg.OriginalHeight * L / Jpeg.OriginalWidth
Jpeg.Save Server.MapPath("gallery") & "\small_" & File.FileName
companyName = Upload.Form("companyName")
address = Upload.Form("address")
addressFr = Upload.Form("addressFr")
telephone = Upload.Form("telephone")
fax = Upload.Form("fax")
tollfree = Upload.Form("tollfree")
desc = Upload.Form("desc")
descFr = Upload.Form("descFr")
imagePath = "gallery" & "\" & File.Filename
imagePathSmall = "gallery" & "\" & "small_" & File.Filename
Set imageRS = Server.CreateObject ("ADODB.Recordset")
imageRS.Open "images", strConnect, adOpenStatic, adLockOptimistic, adCmdTable
if imageRS.BOF then
imageRS("companyName") = companyName
imageRS("address") = address
imageRS("addressFr") = addressFr
imageRS("telephone") = telephone
imageRS("fax") = fax
imageRS("tollfree") = tollfree
imageRS("desc") = desc
imageRS("descFr") = descFr
imageRS("imagePath") = imagePath
imageRS("imagePathSmall") = imagePathSmall
Set imageRS = Nothing
<IMG SRC="gallery/<% = "small_" & File.FileName %>">
Just query the database before you insert the data and check to see if the companyName and/or other information still exists. If it exists then don't insert it again. Simple.
There are more logical ways to do it, but I think that would be the easiest with your current code.
'imageRS.Open "images", strConnect, adOpenStatic, adLockOptimistic, adCmdTable
imageRs.Open "SELECT * FROM [images] WHERE [companyName]='"&companyName&"' AND [address]='"&address&"'", strConnect, adOpenStatic, adLockOptimistic
if imageRS.EOF then ' //If the current companyName/address combination does not exixt then add it.
imageRS . AddNew
imageRS ( "companyName" ) = companyName
imageRS ( "address" ) = address
imageRS ( "addressFr" ) = addressFr
imageRS ( "telephone" ) = telephone
imageRS ( "fax" ) = fax
imageRS ( "tollfree" ) = tollfree
imageRS ( "desc" ) = desc
imageRS ( "descFr" ) = descFr
imageRS ( "imagePath" ) = imagePath
imageRS ( "imagePathSmall" ) = imagePathSmall
imageRS . Update
imageRS . Close
Set imageRS = Nothing
Last edited by WoD; 07-12-2005 at
I tried this code, and now I am getting only the one image added with one instance of the info.
Can you suggest a more logical way to do this? I am just starting to work with this stuff, so am still a little green.
Ah, I didn't read what I was writing properly.
The LOGICAL way to do this is to apply some "database normalisation" and split your company information and image information into TWO separate tables.
So, company information table would be:
ID - Autonumber
And your image information table would be:
ID - Autonumber
You then insert the company information ONCE into the company information table, after the RS.Update you retrieve the autonumber ID (CompanyID = RS("ID") and then use that ID when you insert the four images into the image information table to create a relationship.
Users Browsing this Thread
There are currently 1 users browsing this thread.
(0 members and 1 guests)