Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Capturing Form Data and CREATING A TABLE FROM IT


Message #1 by Leo Clayton <claytonl@z...> on Wed, 18 Oct 2000 16:50:26 -0400
--=====================_20121683==_.ALT

Content-Type: text/plain; charset="us-ascii"; format=flowed



I have just created a FORM with CHECKBOXES from the following code:

<%

strSQL = "SELECT * FROM SkillsTable;"

Set DbObj = Server.CreateObject("ADODB.CONNECTION")

DbObj.Open "DSN=EmployeeMaster"

Set oRs = DbObj.Execute(strSQL)

%>



<FORM ACTION="CreateSkillsRecord2.asp" METHOD="POST"  id=form1 

name=SelectingSkills>

<TABLE BORDER=0>



<% Do WHILE NOT oRs.EOF

Response.Write("<tr>")

         For i = 1 to 3

                         If not oRs.EOF Then

                                 Response.Write(_

                                 "<td><input type=Checkbox name=skill>" &_

                                 "<td>  " & 

oRs.Fields("SkillName").Value & "</td>")

                                 oRs.MoveNext

                         Else

                                 Response.Write(_

                                 "<td> </td>" &_

                                 "<td> </td>")

                 End If

         Next



         Response.Write(_

                 "</tr>")

         Loop

  %>

</TABLE>

and it works!



Now I need to read this FORM to create a RECORD in a TABLE whenever there 

is a check in the box.



I won't know in advance how many boxes will be checked.



I'm STUCK!!




Message #2 by "Ken Schaefer" <ken@a...> on Thu, 19 Oct 2000 16:34:05 +1000
duh, the code below wont work, due to a syntax error...



Try:



For x = 1 to Request.Form("skills").Count



<Ken smacks himself in the head>



----- Original Message -----

From: "Ken Schaefer" <ken@a...>

To: "ASP Databases" <asp_databases@p...>

Sent: Thursday, October 19, 2000 12:20 PM

Subject: Re: [asp_databases] Capturing Form Data and CREATING A TABLE FROM

IT





> I'd suggest that you'd need two tables.

> One to store the person, and one to store the skills associated with the

> person.

> You also need to assign a value="" to each checkbox. If you don't assign a

> value, nothing is going to be passed across...

>

> --- page2.asp ---

>

> If Request.Form("skills").Count then

>     ' At least one checkbox was checked so insert data

>

>     For each x in 1 to Request.Form("skills").Count

>         strSQL = "INSERT INTO table2 "

>         strSQL = strSQL & "(UserID, SkillID) "

>         strSQL = strSQL & "VALUES ( "

>         strSQL = strSQL & intPersonID & ", "

>         strSQL = strSQL & Request.Form("skills")(x) & ")"

>

>         objConn.execute(strSQL)

>     Next

> End if

>

> HTH

>

> Cheers

> Ken







Message #3 by "Ken Schaefer" <ken@a...> on Thu, 19 Oct 2000 12:20:03 +1000
I'd suggest that you'd need two tables.

One to store the person, and one to store the skills associated with the

person.

You also need to assign a value="" to each checkbox. If you don't assign a

value, nothing is going to be passed across...



--- page2.asp ---



If Request.Form("skills").Count then

    ' At least one checkbox was checked so insert data



    For each x in 1 to Request.Form("skills").Count

        strSQL = "INSERT INTO table2 "

        strSQL = strSQL & "(UserID, SkillID) "

        strSQL = strSQL & "VALUES ( "

        strSQL = strSQL & intPersonID & ", "

        strSQL = strSQL & Request.Form("skills")(x) & ")"



        objConn.execute(strSQL)

    Next

End if



HTH



Cheers

Ken



----- Original Message -----

From: "Leo Clayton" <claytonl@z...>

To: "ASP Databases" <asp_databases@p...>

Sent: Thursday, October 19, 2000 6:50 AM

Subject: [asp_databases] Capturing Form Data and CREATING A TABLE FROM IT





> I have just created a FORM with CHECKBOXES from the following code:

> <%

> strSQL = "SELECT * FROM SkillsTable;"

> Set DbObj = Server.CreateObject("ADODB.CONNECTION")

> DbObj.Open "DSN=EmployeeMaster"

> Set oRs = DbObj.Execute(strSQL)

> %>

>

> <FORM ACTION="CreateSkillsRecord2.asp" METHOD="POST"  id=form1

> name=SelectingSkills>

> <TABLE BORDER=0>

>

> <% Do WHILE NOT oRs.EOF

> Response.Write("<tr>")

>          For i = 1 to 3

>                          If not oRs.EOF Then

>                                  Response.Write(_

>                                  "<td><input type=Checkbox name=skill>" &_

>                                  "<td>  " &

> oRs.Fields("SkillName").Value & "</td>")

>                                  oRs.MoveNext

>                          Else

>                                  Response.Write(_

>                                  "<td> </td>" &_

>                                  "<td> </td>")

>                  End If

>          Next

>

>          Response.Write(_

>                  "</tr>")

>          Loop

>   %>

> </TABLE>

> and it works!

>



> Now I need to read this FORM to create a RECORD in a TABLE whenever there

> is a check in the box.

>

> I won't know in advance how many boxes will be checked.

>

> I'm STUCK!!

>


  Return to Index