Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-17-2012, 03:55 AM   PM User | #1
keithboesker
New Coder

 
Join Date: Dec 2011
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
keithboesker is an unknown quantity at this point
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.
keithboesker is offline   Reply With Quote
Old 10-17-2012, 08:13 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 10-17-2012, 11:04 PM   PM User | #3
keithboesker
New Coder

 
Join Date: Dec 2011
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
keithboesker is an unknown quantity at this point
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.
keithboesker is offline   Reply With Quote
Old 10-17-2012, 11:44 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 10-18-2012, 02:38 AM   PM User | #5
keithboesker
New Coder

 
Join Date: Dec 2011
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
keithboesker is an unknown quantity at this point
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.
keithboesker is offline   Reply With Quote
Old 10-18-2012, 08:42 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
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.
Old Pedant is offline   Reply With Quote
Old 10-19-2012, 04:07 AM   PM User | #7
keithboesker
New Coder

 
Join Date: Dec 2011
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
keithboesker is an unknown quantity at this point
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.
keithboesker is offline   Reply With Quote
Old 10-19-2012, 07:46 PM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:16 AM.


Advertisement
Log in to turn off these ads.