SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Thread: updating form

  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    updating form

    hey guys, im working on a form where ppl can update infos in the DB, including images (so if there's no image, they can add, if there's an image, they can change it)

    the problem is with the images, i want to know if there's a quick way to check which fields in the form have been changed and then update only them...
    atm i got it like that:
    Code ASP:
    if FileOK = false and fileOK2 = false and FileOK3 = false and FileOK4 = false then
    Updating = "update Animals set [Type]='" & sType & "', AnimalType='" & AnimalType1 & "', AdoptionStatus='" & AdoptionStatus1 & "', [Desc]='" & Desc1 & "', PetName='" & name1 & "' where FileID=" & session("ID")
    elseif FileOK = true and fileOK2 = false and FileOK3 = false and FileOK4 = false then
    Updating = "update Animals set [Type]='" & sType & "', AnimalType='" & AnimalType1 & "', AdoptionStatus='" & AdoptionStatus1 & "', [Desc]='" & Desc1 & "', PetName='" & name1 & "', FileName='" & FileName & "' where FileID=" & session("ID")
    elseif FileOK = true and fileOK2 = true and FileOK3 = false and FileOK4 = false then
    Updating = "update Animals set [Type]='" & sType & "', AnimalType='" & AnimalType1 & "', AdoptionStatus='" & AdoptionStatus1 & "', [Desc]='" & Desc1 & "', PetName='" & name1 & "', FileName='" & FileName & "', FileName2='" & FileName2 & "' where FileID=" & session("ID")
    elseif FileOK = true and fileOK2 = true and FileOK3 = true and FileOK4 = false then
    Updating = "update Animals set [Type]='" & sType & "', AnimalType='" & AnimalType1 & "', AdoptionStatus='" & AdoptionStatus1 & "', [Desc]='" & Desc1 & "', PetName='" & name1 & "', FileName='" & FileName & "', FileName2='" & FileName2 & "', FileName3='" & FileName3 & "' where FileID=" & session("ID")
    elseif FileOK = true and fileOK2 = true and FileOK3 = true and FileOK4 = true then
    Updating = "update Animals set [Type]='" & sType & "', AnimalType='" & AnimalType1 & "', AdoptionStatus='" & AdoptionStatus1 & "', [Desc]='" & Desc1 & "', PetName='" & name1 & "', FileName='" & FileName & "', FileName2='" & FileName2 & "', FileName3='" & FileName3 & "', FileName4='" & FileName4 & "' where FileID=" & session("ID")

    While FileOK, FileOK2, FileOK3, FileOK4 are checking which file have been changed (fileok for file1, fileok2 for file2 etc etc)

    Yeah, terrible lol and its not even close to an end, there's like unlimited options to which image have been changed exactly (also deleting the current image from the folder, uploading the new one.....)

    Well i just wanna know if there's any quick way of doing this wiithout all those endless lines of IFs

    thanks in advance

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    oh nvm that, found something that does the job well
    Code ASP:
    Updating = "update Animals set [Type]='" & sType & "', AnimalType='" & AnimalType1 & "', AdoptionStatus='" & AdoptionStatus1 & "', [Desc]='" & Desc1 & "', PetName='" & name1 & "' where FileID=" & session("ID")
    Conn.execute Updating
    if size > 0 then
    Updating = "update Animals set FileName='" & FileName & "' where FileID=" & session("ID")
    Conn.execute Updating
    end if
    if size2 > 0 then
    Updating = "update Animals set FileName2='" & FileName2 & "' where FileID=" & session("ID")
    Connexecute Updating
    end if
    if size3 > 0 then
    Updating = "update Animals set FileName3='" & FileName3 & "' where FileID=" & session("ID")
    Conn.execute Updating
    end if
    if size4 > 0 then
    Updating = "update Animals set FileName4='" & FileName4 & "' where FileID=" & session("ID")
    Conn.execute Updating
    end if

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code ASP:
    sSQL = "UPDATE Animals set [Type]='" & sType & "', AnimalType='" & AnimalType1 & "', AdoptionStatus='" & AdoptionStatus1 & "', [Desc]='" & Desc1 & "', PetName='" & name1 & "'"
    If size > 0 Then sSQL = sSQL & ", FileName='" & FileName & "'"
    If size2 > 0 Then sSQL = sSQL & ", FileName2='" & FileName2 & "'"
    If size3 > 0 Then sSQL = sSQL & ", FileName3='" & FileName3 & "'"
    If size4 > 0 Then sSQL = sSQL & ", FileName4='" & FileName4 & "'"
    sSQL = sSQL & " WHERE FileID=" & session("ID")
    Conn.Execute sSQL
    Does the same, but with only ONE database transaction.
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    oh nice, but what i posted was without all the rest of the process :P its the first time i have Delete, upload and update in one page, its loooooong


    Code:
    if size > 0 then
    Pic1 = rs("FileName")
    if Pic1 <> "" then
    Set MyFile = fso.GetFile(Server.Mappath("db") & "\PetPhotos\" & pic1)
    MyFile.Delete
    set MyFile = nothing
    end if
    FileName = Upload.UniqueName(folder, FileName)
    Upload("File1").SaveAs Folder & FileName
    Updating = "update Animals set FileName='" & FileName & "' where FileID=" & session("ID")
    Conn.execute Updating
    end if
    And since now i upload images to a folder i also need to make sure they get a uniqueName, means ill first have to upload and only then add each one through a different SQL command, so i cant really use ur SQL command

    but i still got a problem having it to run properly, one of the pages of Lewis moten's (CLSupload) always throws me an error and i have no idea what it means
    Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

    at:
    Code:
    BinaryStream.Type = adTypeBinary
    any ideas?

  5. #5
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Has the adTypeBinary constant been defined already elsewhere in the code? (Either via an include file, or at the top of the class, or as a TYPELIB declaration)
    Ian Anderson
    www.siteguru.co.uk

  6. #6
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    after what u said i decided to copy the CLSupload file from my backup and it started working, seems like i deleted some line i needed..

    I need an advice, probably the last thing and im done with the updating page, the deleting part

    Near each image im going to put a Checkbox, each one got an ID (1,2,3,4 in that case)

    if any of the checkbox is checked, on the next page it checks which ID is checked and deletes the File (also from the folder and also the name from the table)

    The question is how do i check which number is checked? i remmeber with the sCB method i get something like 1,2,4
    How do i make it so if ID 1 then Delete FileName
    if ID 2 then Delete fileName2

    etc...
    Thanks for the help

  7. #7
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You'll need to do it in stages.

    First, get which checkboxes are checked.

    Next, run a SQL to extract the filenames from the database relating to that FileID. Build the SQL something like:
    Code:
    sSQL = "SELECT "
    If sCB1 Then sSQL = sSQL & "Filename,"
    If sCB2 Then sSQL = sSQL & "Filename2,"
    If sCB3 Then sSQL = sSQL & "Filename3,"
    If sCB4 Then sSQL = sSQL & "Filename4,"
    sSQL = Left(sSQL, Len(sSQL)-1) 'To remove the last comma
    sSQL = sSQL & " FROM Animals WHERE FileID=" & Session("ID")
    Run the SQL to get the values.

    Run code to delete the files.

    Run a SQL to delete filenames from the database. (Build it along the same lines as above).
    Code:
    sSQL = "DELETE "
    If sCB1 Then sSQL = sSQL & "Filename,"
    If sCB2 Then sSQL = sSQL & "Filename2,"
    If sCB3 Then sSQL = sSQL & "Filename3,"
    If sCB4 Then sSQL = sSQL & "Filename4,"
    sSQL = Left(sSQL, Len(sSQL)-1) 'To remove the last comma
    sSQL = sSQL & " FROM Animals WHERE FileID=" & Session("ID")
    Something along those lines anyway.
    Ian Anderson
    www.siteguru.co.uk

  8. #8
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    uhm, it doesn't do anything, there's probably something wrong with me getting the CB so the IFs always getting false

    what is sCB2, sCB3 etc? where are they coming from?
    i just used sCB = Request.Form("cb") ;P

    And in the form its self it was
    type=Checkbox name=cb value=2
    type=Checkbox name=cb value=3
    type=Checkbox name=cb value=4

  9. #9
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well i got it working but now i found out that if none of the CBs are selected to be deleted, then your SQL would delete the whole record
    any other way of doing this?

    or when i try in a different way, i get this error :
    Command text was not set for the command object.
    on this:
    Code:
    DelPics = "DELETE FileName2 from Animals where FileID=" & Session("ID")
    Conn.Execute(DelPets)

  10. #10
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Conn.Execute(DelPics)

    Yeah re. delete the record - but what I posted was to give inspiration, not to be a drop-in-and-use-exact set of code.
    Ian Anderson
    www.siteguru.co.uk

  11. #11
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    oh, didnt see that

    The following form does deletes the required file from the folder correctly, but when getting to the delete SQL, it always deletes the whole record...whats the problem there ?:/

    Code:
    if sCB2 = 2 then 
    Pic1 = CallToPets("FileName2")
    Set MyFile = fso.GetFile(Server.Mappath("db") & "\PetPhotos\" & pic1)
    MyFile.Delete
    set MyFile = nothing
    DelPics = "DELETE FileName2 from Animals where FileID=" & Session("ID")
    ConnToPets.Execute(DelPics)
    end if
    Edit * well for now i decided to use this and it started working...:
    Code ASP:
    "update Animals set FileName2='' where FileID=" & session("ID")

    but now i got another thing which isnt working, i wanna check if a dog is a month dog and also adoption status = not available
    if yes then change it to dog and do the SQL else do the SQL normally
    for some reason, it always goes to the ELSE even when it should do the first SQL

    Code:
    if sType = "month dog" and AdoptionStatus1 = "not available" then
      sType = "dog"
      Updating = "update Animals set [Type]='" & sType & "', AnimalType='" & AnimalType1 & "', AdoptionStatus='" & AdoptionStatus1 & "', [Desc]='" & Desc1 & "', PetName='" & name1 & "' where FileID=" & session("ID")
    Else
      Updating = "update Animals set [Type]='" & sType & "', AnimalType='" & AnimalType1 & "', AdoptionStatus='" & AdoptionStatus1 & "', [Desc]='" & Desc1 & "', PetName='" & name1 & "' where FileID=" & session("ID")
    end if

  12. #12
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    nvm got it working aswell, it supposed to be AnimalType1 not sType

  13. #13
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Re. deleting the record ... oops!

    Yeah - you need to UPDATE the record to set the field values blank.
    Ian Anderson
    www.siteguru.co.uk


Bookmarks

Posting Permissions

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