?
Solved

insert multiple records into 1 table by using checkboxes

Posted on 2003-03-27
6
Medium Priority
?
398 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:frikkiefrik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 15

Expert Comment

by:gladxml
ID: 8216723
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
 
LVL 5

Expert Comment

by:MMeijer
ID: 8216762
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
 
LVL 15

Expert Comment

by:gladxml
ID: 8216798
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Accepted Solution

by:
gladxml earned 500 total points
ID: 8216829
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
 
LVL 15

Expert Comment

by:gladxml
ID: 8216911
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
 
LVL 58

Expert Comment

by:Gary
ID: 9187858
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 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