• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 543
  • Last Modified:

aspupload using multiple checkboxes with the same name

Hello, I found part of the solution and i have all the field info response.writing but i don't know how to get the values to combine as a comma delimited string to enter into the database. Below is the test i set up. and here is what the page looks like:
title= 44444444
action= insert
sec= Symptoms
section= Symptoms
content_type= ABOUT
FCKeditor1=
Enter content body copy here


user_types= SELFCARE
user_types= CAREGIVER
user_types= PROVIDER
age_group= CHILD
age_group= TEEN
age_group= ADULT
age_group= SENIOR
co_morbid= Obesity
co_morbid= Cardiovascular Disease/Heart Disease
co_morbid= Hypertension/High Blood Pressure
co_morbid= Foot Disease
description=
Submit= Insert this record


i need to get user_types, age_group and co_morbid to enter into the database as a comma delimited string.
<!--#include file="variables_set.asp"-->
<!--#include file="connection.asp"-->
 
<%
	Set Upload = Server.CreateObject("Persits.Upload")
Dim cont_id,sec
 
	' we use memory uploads, so we must limit file size - THIS IS SET TO 50mb
	Upload.SetMaxSize 26214400, True
 
	' Save to memory. Path parameter is omitted
	Count = Upload.Save
 
	' Obtain file object
	Set File = Upload.Files("THEFILE")
 
		' Build ADO connection string
		'Connect = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath(".\aspupload.mdb")
cont_id=Upload.form("id")
sec=Upload.form("sec")
		' If you use SQL Server, the connecton string must look something like this:
		 Connect = "Provider=SQLOLEDB;Server=67.59.176.188;Database="&dbasename&";UID=velocity;PWD=********y"
 
		' Use ADO Recordset object
		Set rs = Server.CreateObject("adodb.recordset")
 
		' Optional: check whether this file already exists using MD5 hash
		'Hash = File.MD5Hash
		'rs.Open "SELECT * from DOCS WHERE Hash='" & Hash & "'", Connect, 2, 3
		'If Not rs.EOF Then
		'prod_id=Upload.Form("prod_id")
			'Response.redirect"doc_new.asp?stat=filefound&prodid="&prod_id&"&prod="&prodname&""
		'End If
		'rs.Close
		' Reopen recordset to insert file
rs.Open "CONTENT", Connect, 3, 3 
   
   rs.AddNew
rs("title") = Upload.Form("title")
rs("content_type") = Upload.Form("content_type")
rs("section") = Upload.Form("section")
 
For Each Item in Upload.Form
       Response.Write Item.Name & "= " & Item.Value & "<BR>"
    Next
Set Upload = Nothing
 
 
 
 
%>

Open in new window

0
remedy_rider
Asked:
remedy_rider
  • 6
  • 5
1 Solution
 
MaxOvrdrv2Commented:
do you work for the government by any chance? this is going towards a CMS type application as well?

you don't have to answer of course, i'm simply curious... ;)

here's the solution.
For Each Item in Upload.Form
   if Item.Name="user_types" OR Item.Name="age_group" OR Item.Name="co_morbid" then
      RS("yourfieldname")=RS("youfieldname") & Item.Value & ","
   end if
Next
RS("yourfieldname")=left(RS("yourfieldname"),RS("yourfieldname").length-1)

Open in new window

0
 
remedy_riderAuthor Commented:
LOL... me... government. that's funny. Nope, just working on a diabetes site. I was able to get the values in using your code. I needed them to go into their own fields which i figured out,  but i'm stuck on stripping out the trailing comma. :(  any ideas? I attached the code snipplet i have working.
for example, this is what the user_types field looks like when i selected all check boxes.
SELFCARE,CAREGIVER,PROVIDER,

just need to get rid of  the comma at the end.

 I really appreciate the help!
rs.Open "CONTENT", Connect, 3, 3 
   
   rs.AddNew
   For Each Item in Upload.Form
   if Item.Name="user_types"  then
      RS("user_types")=RS("user_types") & Item.Value & ","
   end if
 
   if Item.Name="age_group" then
      RS("age_group")=RS("age_group") & Item.Value & ","
   end if
 
   if Item.Name="co_morbid" then
      RS("co_morbid")=RS("co_morbid") & Item.Value & ","
   end if
   
      if Item.Name="related_sections" then
    RS("related_sections") =RS("related_sections") & Item.Value & ","
   end if
Next
rs("title") = Upload.Form("title")
rs("content_type") = Upload.Form("content_type")
rs("section") = Upload.Form("section")
rs("sub_section") = Upload.Form("sub_section")
rs("body_content") = Upload.Form("FCKeditor1")
rs("created") = date()
rs("modified") = date() & " " & time()
   rs.Update
   
   rs.movelast
   new_id = rs("id")
   section= rs("section")
   con_type=rs("content_type")
    set rs = Nothing

Open in new window

0
 
MaxOvrdrv2Commented:
ah HA! you missed the final line in my solution ;) here it is, inside your code:
  if Item.Name="related_sections" then
    RS("related_sections") =RS("related_sections") & Item.Value & ","
   end if
Next
RS("related_sections")=left(RS("related_sections"),RS("related_sections").length-1)
 
perform the same for each other DB field that you created in this way... ;)

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
remedy_riderAuthor Commented:
bummer: Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'rs(...).length'

/d_CARE/cms/content-insert.asp, line 56
0
 
remedy_riderAuthor Commented:
I got it. :) RS("related_sections")=Left(RS("related_sections"), Len(RS("related_sections")) - 1)

You really helped me through that one, thanks again Max!
0
 
MaxOvrdrv2Commented:
oh, crap... just a sec i'll look up the proper way to find out the length of a string...

ok here it is... i was in .Net... my bad...
RS("related_sections")=left(RS("related_sections"),len(RS("related_sections"))-1)
 
perform the same for each other DB field that you created in this way... 

Open in new window

0
 
MaxOvrdrv2Commented:
yes there you go! hehe! sorry again... my mind was in .Net mindset =)
0
 
remedy_riderAuthor Commented:
I forgot to ask about the update script. i'm close but no cigar. here's what the sql is writing:

Update CONTENT Set title='TESTING NEWS NEW INSERT SCRIPT', user_types='SELFCARE, CAREGIVER, PROVIDERPROVIDER', age_group='CHILD,TEEN, ADULT, SENIORSENIOR', co_morbid='Foot Disease', related_sections='Behavior & Lifestyle Management, Complications, Prevention & Risk Reduction, Testing & MonitoringTypes of Diabetes', content_type='NEWS', section='', sub_section='', body_content='
Enter content body copy hereASDFASDFASDF

', modified='5/12/2009 3:46:33 PM' where id=335


you can see it's getting rid of the last comma, then adding the last value? and i added multiple items in co_morbid and it's only bringing 1 over. It's probably something so easy, just having a rough day and can't seem to move forward. (except for your help! it's the only thing getting me though this day)
	rs.Open "CONTENT", conn, 3, 3 
		For Each Item in Upload.Form
   if Item.Name="user_types"  then
      user_types=RS("user_types") & Item.Value & ","
   end if
 
   if Item.Name="age_group" then
      age_group=RS("age_group") & Item.Value & ","
   end if
 
   if Item.Name="co_morbid" then
      co_morbid=RS("co_morbid") & Item.Value & ","
   end if
   
    if Item.Name="related_sections" then
   related_sections =RS("related_sections") & Item.Value & ","
   end if
Next
 
	sql = "Update CONTENT Set title='" & replace(Upload.form("title"),"'", "`") & "'"
sql = sql & ", user_types='" & Left(user_types, Len(user_types) - 1)& "'"
sql = sql & ", age_group='" & Left(age_group, Len(age_group) - 1)& "'"
sql = sql & ", co_morbid='" & Left(co_morbid, Len(co_morbid) - 1)& "'"
sql = sql & ", related_sections='" & Left(related_sections, Len(related_sections) - 1)& "'"
	sql = sql & ", content_type='" & replace(Upload.form("content_type"),"'", "`") & "'"
	sql = sql & ", section='" & replace(Upload.form("section"),"'", "`") & "'"
	sql = sql & ", sub_section='" & replace(Upload.form("sub_section"),"'", "`") & "'"
	sql = sql & ", body_content='" & replace(Upload.form("FCKeditor1"),"'", "`") & "'"
	sql = sql & ", modified='" & date() & " " & time()& "'"
	sql = sql & " where id="& Upload.form("id")
	response.write sql
	Set rs = conn.Execute(sql)
	new_id=Upload.form("id")
   sec= Upload.form("section")
   con_type=Upload.form("content_type")
 
    set rs = Nothing

Open in new window

0
 
remedy_riderAuthor Commented:
got it... sorry to keep posting and figuring it out. LOL. I just couldn't let it go. :) thanks for looking into all this for me. it's been SUPER helpful.
0
 
MaxOvrdrv2Commented:
ok... lets take a look at the code... ok ok... so if you copy the code below, what do you get in your final statement? i didn't change much, but i'd like to see what you get...
rs.Open "CONTENT", conn, 3, 3 
For Each Item in Upload.Form
	if Item.Name="user_types"  then
		user_types=RS("user_types") & Item.Value & ","
	end if
	if Item.Name="age_group" then
		age_group=RS("age_group") & Item.Value & ","
	end if
	if Item.Name="co_morbid" then
		co_morbid=RS("co_morbid") & Item.Value & ","
	end if
	if Item.Name="related_sections" then
		related_sections =RS("related_sections") & Item.Value & ","
	end if
Next
 
	sql = "Update CONTENT Set title='" & replace(Upload.form("title"),"'", "`") & "'"
	sql = sql & ", user_types='" & Left(user_types, Len(user_types) - 1) & "'"
	sql = sql & ", age_group='" & Left(age_group, Len(age_group) - 1) & "'"
	sql = sql & ", co_morbid='" & Left(co_morbid, Len(co_morbid) - 1) & "'"
	sql = sql & ", related_sections='" & Left(related_sections, Len(related_sections) - 1)& "'"
	sql = sql & ", content_type='" & replace(Upload.form("content_type"),"'", "`") & "'"
	sql = sql & ", section='" & replace(Upload.form("section"),"'", "`") & "'"
	sql = sql & ", sub_section='" & replace(Upload.form("sub_section"),"'", "`") & "'"
	sql = sql & ", body_content='" & replace(replace(Upload.form("FCKeditor1"),"'", "`"),VBCrlF,"<br>") & "'"
	sql = sql & ", modified='" & date() & " " & time()& "'"
	sql = sql & " where id="& Upload.form("id")
	response.write sql
	response.end

Open in new window

0
 
MaxOvrdrv2Commented:
actually, use this loop instead please:
For Each Item in Upload.Form
	if Item.Name="user_types"  then
		user_types=user_types & Item.Value & ","
	end if
	if Item.Name="age_group" then
		age_group=age_group & Item.Value & ","
	end if
	if Item.Name="co_morbid" then
		co_morbid=co_morbid & Item.Value & ","
	end if
	if Item.Name="related_sections" then
		related_sections=related_sections & Item.Value & ","
	end if
Next

Open in new window

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now