[quoted text, click to view] Gaby wrote:
> im trying to make an online survey. the answers are different check
> boxes.
> I have this written out already. maybe you guys can help.
> ill give you the abbreviated sample of it:
>
> -------
>
> <HTML>
>
> <HEAD>
>
> <TITLE>Sample</title>
> <%
> strFilePath = server.MapPath("database.mdb")
>
> strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFilePath
> & ";"
> Set rst = Server.CreateObject("ADODB.Recordset")
> rst.LockType = 2
>
> %>
>
> <%
> 'opening database connection
>
> 'add record to my table
>
> FUNCTION WriteToFile()
> strSQL = "SELECT * FROM Table1"
> rst.Open strSQL, strConn
>
> rst.addnew
>
> rst("ID#") = request.form ("ID#")
> rst("Name") = request.form ("Name")
>
>
>
> rst("Box1") = request.form ("Box2")
> rst("Box2") = request.form ("Box2")
>
>
>
> rst.Update
> rst.Close
> End Function
> %>
> </HEAD>
> <BODY>
>
> <FORM name= frmTEST1 method=post action= >
>
>
> <Select name="menu" >
> <option value="Instructor">Select Name</option>
> <option value="Name1"> Name1</option>
> <option value="Name2"> Name2</option>
> </select>
>    
>
> </Select>
>    
>
> ID#.
> <input type="text" size="12" maxlength="6" name="ID#" value="ID#"
> id="ID##" />
> <br>
> <br>
>
> 01. <input type="checkbox" id="box1" name="box1" value="1" /> <label
> for="box1">This is statement 1</label>
> <BR>
> 02. <input type="checkbox" id="box2" name="box2" value="1" /> <label
> for box2">This is statement2</label>
> <BR>
>
> <Center>
>
> ' --- SUBMIT BUTTON ---- />
> <INPUT TYPE='submit' value="Submit" name="Submit_ICL"
> onClick="WriteToFile();">
>
> </FORM>
>
> --------
>
> This is a short sample of the code i have. When i try it the page
> reloads and the answers reset but the info is ot going to the database.
> i know im missing the action=___ whenever i declare my form but i dont
> know what to put or if what im missing that will make mine work.
> eventually i will work on validating it but for know can someone pleae
> help
To start with, don't create a recordset to add a new record. Second,
you have a javascript call to a function - onClick="WriteToFile() -
calling server side asp code. That won't work. Third, you are trying
to reference an input called Name that doesn't exist on your form.
Here's your form:
<form name="frmTEST1" method="post">
<select name="Instructor" >
<option value="">Select Name</option>
<option value="Name1"> Name1</option>
<option value="Name2"> Name2</option>
</select>
<p>
ID#.
<input type="text" size="12" maxlength="6" name="ID#" id="ID##" />
</p>
<p>
01. <input type="checkbox" id="box1" name="box1" value="1" /> <label
for="box1">This is statement 1</label>
</p>
<p>
02. <input type="checkbox" id="box2" name="box2" value="1" /> <label
for box2">This is statement2</label>
</p>
<p>
<input type="submit" value="Submit" name="Action" />
</p>
</form>
In the same page, do this:
<%
On Error Resume Next
If Request.Form("Action") = "Submit" Then
strFilePath = server.MapPath("database.mdb")
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFilePath
conn.open strConn
p1 = Request.Form("Instructor")
p2 = clng(Request.Form("ID#"))
p3 = cint(Request.Form("Box1"))
p4 = cint(Request.Form("Box2"))
If Err.Number<>0 Then
Response.Write "Your record has not been added"
Else
conn.qInsertRecord p1, p2, p3, p4
Response.Write "Your record has been added"
End If
End If
%>
Now, in your database, go to the Query pane and select New Query in
Design View. Close the Show Tables dialogue box that opens, then click
the SQL button in the top left. In the new window that opens, copy
this in, making the necessary changes for your table and field names:
INSERT INTO Table1 (ID#, Instructor, Box1, Box2) VALUES ([p1], [p2],
[p3], [p4])
Save that as qInsertRecord. Then run the query and enter values as
prompted to make sure it works. If it does, that's it. You're done.
--
Mike Brind