PDA

View Full Version : how to save the checkbox value into database using asp?



SBUH
August 30th, 2003, 03:07 PM
Hello, friends. I have form like

input name="checkbox1" type="checkbox" value=""

input name="checkbox2" type="checkbox" value=""


I wonder how to save the checkbox value after the user click. I am beginner that I don't even know what kind of value it should save. Can it be 1 or 0 for check or not?


How should I write the code then?


Thanks in advance and wait for your reply!

Digitalosophy
August 30th, 2003, 09:17 PM
Ok first for your form:


input name="checkbox" type="checkbox" value="ck1"

input name="checkbox" type="checkbox" value="ck2"


ASP File.


<% @ Language=VBScript %>
<%
cbx=Request.Form("checkbox")

MyPath=Server.MapPath("yourDB.mdb") %>

Set conn = Server.CreateObject("ADODB.Connection")

conn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & MyPath

SQL = "INSERT INTO table (value) VALUES ('"&cbx&"')"

Set r = conn.Execute(SQL)
%>


The best way to trouble shoot something like this is before you go ahead and try to insert the actual data, make sure your receiving the variable from your form.



<% @ Language=VBScript %>
<%
cbx=Request.Form("checkbox")
%>
<%=cbx%>


You should see the correct info from the form.

Also be sure to change the table and value of the SQL statement.

Hope this helps