insert multiple records into 1 table by using checkboxes

I need a solution to insert multiple records into 1 table, but only those wich are "checked".
So I have a form with 2 fields and 1 checkbox on each line. There are 10 lines wich can be checked and also must be inserted when they are checked. Can anyone give me a solution for this ? Thanks in advance. Greetings from Belgium.
frikkiefrikAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gladxmlCommented:
try tp make your checkbox having the same name then the value will the unique that is extracted formt he db...


try to check out the link for more details...

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20450556.html

0
MMeijerCommented:
give the checkboxes a unique value and a shared name, prefix the names of the other form elements on the same "line" with the value of the checkbox add some unique characters to identify the element.
example:

<html>
<head>
<title>multiline insert</title>
</head>
<body>
<form method="post">
  <table>
   <tr>
    <td><input type="checkbox" name="line" value="line1" /></td>
    <td><input type="text" name="line1name" /></td>
    <td><input type="text" name="line1email" /></td>
   </tr>
   <tr>
    <td><input type="checkbox" name="line" value="line2" /></td>
    <td><input type="text" name="line2name" /></td>
    <td><input type="text" name="line2email" /></td>
   </tr><tr>
    <td colspan="3" align="right"><input type="submit" /></td>
   </tr>
  </table>
</form>


<%
Dim intCount, strName, strEmail, strSql, objConn

If Request.Form("line").Count > 0 Then
  Set objConn = Server.CreateObject("adodb.connection")
  objConn.Open SomeConnectionstring
  For intCount = 1 To Request.Form("line").Count
    strLine = Request.Form("line")(intcount)
    strName = Request.Form(strLine & "name")
    strEmail = Request.Form(strLine & "email")
    strSql = "insert into table([name],[email]) values('" & strName & "','" & strEmail & "');"
    objConn.Execute strSql
  Next
  objConn.Close
  Set objConn = Nothing
End If
%>

</body>
</html>
0
gladxmlCommented:
frikkiefrik,

below is sample code... But you need to make some chnages in the db name, tablename and column bas eon your exisitng db...

 
<%
if request.form("Submit") = "Submit" then

'please change the databsename
'dsn less connection using adodb

Dim oConn, dbPath
dbPath = Server.MapPath("db3.mdb")
Set oConn=Server.CreateObject("ADODB.Connection")
oConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & dbPath & ";"
dim sqlstr, recordaffected

For i = 1 to Request("chkbox").Count
         chkvalue = Request("chkbox")(i)

arraychk = split(request.form(chkvalue),",")

sqlstr="INSERT INTO TABLENAME (cloumnname1, columnname2) values ('" & arraychk(0) & "', " '" & arraychk(0) & "';")
oConn.execute sqlstr, recordaffected, 1
           
 Next

oConn.Close
Set oConn = nothing

end if
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>@</td>
      <td>@</td>
      <td>@</td>
    </tr>
    <%for i=1 to 10%>
    <tr>
      <td>
        <input type="checkbox" name="chkbox" value="<%="field"&i%>">
      </td>
      <td>
        <input type="text" name="<%="field" &i%>">
      </td>
      <td>
        <input type="text" name="<%="field" &i%>">
      </td>
    </tr>
    <%next%>
    <tr>
      <td colspan="3"><input type="submit" name="Submit" value="Submit">
@</td>
    </tr>
  </table>

</form>
</body>
</html>

HTH...

HAppy programming...
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

gladxmlCommented:
frikkiefrik,


ooops there are syntax error on my previous post try to use  this instead...
 

===========
<%
if request.form("Submit") = "Submit" then

'please change the databsename
'dsn less connection using adodb

Dim oConn, dbPath
dbPath = Server.MapPath("db3.mdb")
Set oConn=Server.CreateObject("ADODB.Connection")
oConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & dbPath & ";"
dim sqlstr, recordaffected

For i = 1 to Request("chkbox").Count
         chkvalue = Request("chkbox")(i)

arraychk = split(request.form(chkvalue),",")

sqlstr="INSERT INTO PCUser (test1, test2) values ('" & arraychk(0) & "','" & arraychk(1) & "')"
oConn.execute sqlstr, recordaffected, 1
           
 Next

oConn.Close
Set oConn = nothing

end if
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>@</td>
      <td>@</td>
      <td>@</td>
    </tr>
    <%for i=1 to 10%>
    <tr>
      <td>
        <input type="checkbox" name="chkbox" value="<%="field"&i%>">
      </td>
      <td>
        <input type="text" name="<%="field" &i%>">
      </td>
      <td>
        <input type="text" name="<%="field" &i%>">
      </td>
    </tr>
    <%next%>
    <tr>
      <td colspan="3"><input type="submit" name="Submit" value="Submit">
@</td>
    </tr>
  </table>

</form>
</body>
</html>


HTH..

HAppy programming...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gladxmlCommented:
frikkiefrik,

I test it here and working fine..  here my access test db structure

databasename = db3.mdb
tablename = PCUser
column name = test1 & test2
column datatype = string data type..

HTH...

HAppy programming...
0
GaryCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by gladxml

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.