Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checkboxes not update in asp database

    I have a list of checkboxes like 1,2,3,4,5 when I use update statement I get 1 instead of 1,2,3,4,5 in my database column. I have checked to make sure request.form is returning 1,2,3,4,5 and it is but it only update one value instead of the array of numbers. Is there a simple way to get this to update correctly? Thanks for your help in advance.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,146
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    You do *NOT* want "1,2,3,4,5" in your database column. PERIOD.

    You should *NEVER* store a LIST of values in a single field in a database.

    You should store each checkbox in a SEPARATE RECORD, probably in a separate many-to-one table.

    You don't show us your DB design. You don't show use your code. There's not much more we can help you with until you share more of your problem.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Dec 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is an array and it is a very useful way to get checkboxes info from your users an put it one database column.

    Update statement

    Code:
    NMGroups = Request.Form("NMGroups")
     
    strSQL = "UPDATE NewsletterMembers set NMGroups = '" & NMGroups & "' WHERE NMID =" & NMID
    checkboxes are all name NMGroups with value of 1,2,3,4 etc

    I just need the array of numbers to update to one table called NMGroups in my database. Right now it works in my insert statement but when I us the update statement it only grabs the first number in the array. How do I grad all numbers like 1,2,3,4 and save it.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,146
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    I will say it one more time: That is *TERRIBLE TERRIBLE* database design.

    Even if you only read the first few paragraphs of any book or article on DATABASE NORMALIZATION you will learn that. And any GOOD book or article on database design *WILL* include a section on normalization, guaranteed.

    But if you are going to do this despite what any database designer will tell you, then at least show us the *CODE* that you say is not working.

    What does the design of your table NMGroups look like, for starters? What does the SQL query that you are using to do UPDATE NMGroups ... look like?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Dec 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    NMGroups is a number field in the database. the update script listed below updates but only puts 1 number instead of the array of numbers like 1,2,3,4 my insert statement on a different page works fine. Just when the use goes to update this list it only put 1 number when 1,2,3,4 are checked.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,146
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    NMGroups is a number field
    If that is true, then it can only hold one number. So that would mean your INSERT should not work, either.

    It must be a text field of some kind or it could never hold more than one number.

    *********

    DEBUG DEBUG DEBUG

    Code:
    ...
    NMGroups = Request.Form("NMGroups")
    strSQL = "UPDATE NewsletterMembers set NMGroups = '" & NMGroups & "' WHERE NMID =" & NMID
    
    Response.Write "<hr/>DEBUG SQL: " & strSQL & "<hr/>" & vbNewLine
    
    ...
    If you put in the debug code shown there and run the page, what does the debug output to the screen?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    New Coder
    Join Date
    Dec 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    fixed it I forgot to remove the whitespace used replace(request.form("NMGroups"), " ", "") 1, 2, 3, 4 almost looks like1,2,3,4 when I did the response.write to verify the form.

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,146
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Don't see why a space would matter. The data should have been inserted/update anyway, just that it would have spaces in it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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