Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Insert Using Checkboxes??? 1

Status
Not open for further replies.
May 9, 2000
446
GB
Hi, right here goes,
I've got a page that lists some records, is it possible to have a check box next to each record on the page that the user can select and then have one submit button that will submit all records that have been checked??? The functionality i'm after is for the records to be inserted into an ms access table as seperate records just like the way that hotmail address book inserts the addresses into the 'To' part of the form except I want the records in the a instead.. does that make sense???

Cheers in advance...
 

<%@ Language=VBScript %>
<%
Dim test
test = Request.Form(&quot;fTest&quot;)
Response.Write test
%>
<form action=test.asp method=post>
<input type=checkbox name=fTest value=a>
<input type=checkbox name=fTest value=b>
<input type=checkbox name=fTest value=c>
<input type=checkbox name=fTest value=d>
<input type=submit>
</form>


When you check A and C, press SUBMIT,
the variable fTest will be 'a,c'


br
Gerard
 
Wow, now thats fast! Cheers for getting back, right this might be really slow of me but the variable will hold 'a,c' right what i need is,

Report No. User Update
123 ab checkbox
432 bc checkbox
12341 jh checkbox

So that when the user selects say the checkboxes for report no. 123 and 12341, two seperate records one containing the 123 record data and one containing the 12341 data to be inserted into the database is that what you idea will do??? I don't undertsand!!!!!!!!
Cheers
 
[i'm already with one leg in bed, so this is my last reply for today |-I ]

<%@ Language=VBScript %>
<%
if Request.Form(&quot;fSubmitted&quot;)=&quot;Y&quot; then
Dim cReports, l, n
cReports = Request.Form(&quot;fReport&quot;)
if cReports <> &quot;&quot; then
Response.Write &quot;Selected report(s): &quot; & cReports & &quot;<br>&quot;
' You now parse the string and create an INSERT
' instruction for each report
Response.End
end if
Response.Write &quot;Please check the report(s) you want!&quot;
end if
%>
<form action=test.asp method=post>
<input type=hidden name=fSubmitted value=Y>
<input type=checkbox name=fReport value=123>Ab-report<br>
<input type=checkbox name=fReport value=432>Bc-report<br>
<input type=checkbox name=fReport value=12341>Ju-report<br>
<input type=submit>
</form>


br
Gerard
 
okay, i tried the bit of code above and it returns the values of the selected checkox reports to the same page which is cool, but how do i get the values out of that string??? into the database? where you've put the parse and create insert for each record, i've only done straight forward inserts, updates etc so far!
Cheers
 
You can do a SQL insert for the values returned.
I don't know your database schema, so I'll set up both scenarios for you.

If you want to insert the full comma delimited line, do something like this.

Dim myvar,cn
myvar = Request.Form(&quot;ftest&quot;)

set cn = server.createobject(&quot;adodb.connection&quot;)
cn.open &quot;DSN=mydsn&quot;
cn.execute &quot;INSERT myTable SET col1 = '&quot; & ftest & &quot;'&quot;
cn.close
set cn = nothing

If you want to insert each selected entry, do something like this. This will create a new row in the database table for each entry.

Dim item, cn
set cn = server.createobject(&quot;adodb.connection&quot;)
cn.open &quot;DSN=mydsn&quot;

for each item in request.form(&quot;ftest&quot;)
cn.execute &quot;INSERT mytable SET col1 = '&quot; & item.value & &quot;'&quot;
next
cn.close
set cn = nothing

I hope this helps
leo

 
sorry the correct syntax for the last example is

Dim i
for i = 1 to Request.Form(&quot;ftest&quot;).Count
cn.execute &quot;INSERT mytable SET col1 = '&quot; & request.Form(&quot;ftest&quot;)(i) & &quot;'&quot;
next

you've got to forgive me... i'm still a little groggy from the night before s-)
 
Cool, i'll give it a go, i intend feeling veeeery groggy tommorrow morning!!!
Cheers
 
okay so i've put that code in and the corrected bit and the page runs with no errors but there's no data going into me access database! Oh know this is dragging on but any idea's? I'm using PWS, access '97 if that helps at all....
 
replace the
' You now parse the string and create an INSERT
' instruction for each report
lines in my privious snippet with:

Dim cRepCode, cSQL
set conn = server.CreateObject(&quot;ADODB.Connection&quot;)
conn.open &quot;DSN=TEKTIPS&quot; ' Change this!

do
l = len(cReports)
n = InStr(cReports, &quot;,&quot; )
if n > 0 then
cRepcode = mid(cReports,1,n-1)
cReports = mid(cReports,n+2, l-(n+1))
else
cRepcode = cReports
end if

' change next line. this will try to insert a
' record in a table TEST with field REPCODE.
cSQL = &quot;INSERT INTO TEST (REPCODE)values('&quot; &_
cRepcode & &quot;')&quot;
conn.Execute(cSQL)

if n = 0 then
exit do
end if
loop
conn.Close
set conn = nothing




br
Gerard
 
i'll give it a go tommorrow, i'm off down the pub...

cheers for all ya help..
Gary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top