www.webdeveloper.com
Results 1 to 4 of 4

Thread: ASP Gallery / Database problems ..

Hybrid View

  1. #1
    Join Date
    May 2005
    Posts
    12

    Exclamation ASP Gallery / Database problems ..

    Hello:

    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 ..

    <html>
    <body>
    <%
    'Initial Variables
    Dim strConnect
    '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")

    Upload.Save Server.MapPath("gallery\")

    For Each File in Upload.Files
    If File.ImageType <> "JPG" Then
    Response.Write "This is not a JPEG image."
    File.Delete
    Response.End
    End If

    Jpeg.Open File.Path
    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

    Dim imageRS
    Set imageRS = Server.CreateObject ("ADODB.Recordset")

    imageRS.Open "images", strConnect, adOpenStatic, adLockOptimistic, adCmdTable
    if imageRS.BOF then
    else

    imageRS.MoveLast

    end if

    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
    %>

    <IMG SRC="gallery/<% = "small_" & File.FileName %>">

    <%
    Next
    %>

    </body>
    </html>

  2. #2
    Join Date
    Jan 2005
    Posts
    168
    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.

    Example:

    PHP 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
    end 
    if
    imageRS.Close
    Set imageRS 
    Nothing 
    Last edited by WoD; 07-12-2005 at 10:04 AM.

  3. #3
    Join Date
    May 2005
    Posts
    12
    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.

    Kev,

  4. #4
    Join Date
    Jan 2005
    Posts
    168
    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
    CompanyName
    address
    addressFr
    telephone
    fax
    tollfree
    desc
    descFr

    And your image information table would be:
    ID - Autonumber
    CompanyID
    ImagePath
    ImagePathSmall

    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles