Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

insert multiple records into 1 table by using checkboxes

Posted on 2003-03-27
6
Medium Priority
?
400 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

581 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