Solved

aspupload using multiple checkboxes with the same name

Posted on 2009-05-12
11
520 Views
Last Modified: 2012-05-06
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
Comment
Question by:remedy_rider
  • 6
  • 5
11 Comments
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24366837
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
 

Author Comment

by:remedy_rider
ID: 24367901
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
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24367951
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:remedy_rider
ID: 24368030
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
 

Author Comment

by:remedy_rider
ID: 24368060
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
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24368080
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
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24368087
yes there you go! hehe! sorry again... my mind was in .Net mindset =)
0
 

Author Comment

by:remedy_rider
ID: 24368613
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
 

Author Comment

by:remedy_rider
ID: 24368971
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
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24374135
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
 
LVL 10

Accepted Solution

by:
MaxOvrdrv2 earned 500 total points
ID: 24374164
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question