View Full Version : passing multiple checkbox values to database and retrieving it in displasy.asp
Please can some one help me with the coding to pass multiple checkbox values to database and to retrieve the name and values to the display page. I am creating name list in input form with multiple checkbox and i have created a database with the same name list. Whatever input is checked across the name, should go to the database, and show up in the display page.
Please help!!!!
freejoe76
06-04-2003, 02:10 PM
Why don't you show us some samples of the code you're currently using, as well as the error or roadblock you're up against now?
Sure here is the code:
I have two pages, input.asp and display.asp.
input.asp
<Form action="display.asp" method = "post" name=form1 id = form1>
<input type=checkbox name=sandra value="Sandra">Sandra<br />
<input type=checkbox name=Erika value=Erika<br />
<input type=submit name=submit value="okay">
display.asp
<%
sandra = Request.form("Sandra")
Erika = Request.form("Erika")
%>
<%
Dim Conn, Sql, RS, I
Set Conn = Server.createobject("ADODB.Connection")
Conn.Open "NameList"
sql1 = "Insert into Name(Sandra, Erika) Values('"&Sandra&"', '"&Erika&"')"
Conn.execute sql1, "NameList"
Set Conn = nothing
Set RS = createobject("ADODB.Recordset")
sql = "Select * from Name Order by Date DESC"
RS.Open sql, "NameList"
I=1
%>
<%
Sandra = RS ("Sandra")
Erika = RS("Erika")
%>
<%
For intLoop = 1 to Request.Form.Count
Response.Write Request.Form(intLoop) & "<BR>"
Next
%>
My coding is working and it is passing data to the database as well as to the display page. My problem is that the information is not there when I close and open the browser. I want the information to be there in display page as long as someone changes or updates the information in the input page.
Can someone please help. Thanks.
Is there any one out there who can help with my coding. I can't figure out what is wrong. Infact I tried changing the coding as follows:
input .asp (same as the above one)
result.asp
<%
Set CN = server.createobject("ADODB.Connection")
CN.open "Namelist"
var_sandra = request.form("sandra")
var_erika = request.form("Erika")
sql = "select * from Name Order by Date Desc"
RS.Open Sql,CN,2,2
RS.AddNew
RS("sandra") = var_sandra
RS("Erika") = var_Erika
RS.close
Set RS = nothing
Set CN = nothing
%>
display.asp
<%
Set CN = server.createobject("Adodb.Connection")
CN.Open "Namelist"
sql = "select * from Name Order by Date Desc"
Set RS = server.createobject("Adodb.Recordset")
RS.Open Sql,CN
Do While not record.EOF
Response.write"<b>Sandra:</b>"&record("Sandra").value& "<br />"
Response.write"<b>Erika:</b>"&record("Erika").value&"<br />"
RS.Movenext
Loop
RS.Close
Set RS = nothing
CN.Close
Set CN = nothing
%>
My problem is that I am not able to store the input page info into the database but if I manually go to the server and input info into the database, then it is displaying in display.asp. Please need help. Thanks.
freejoe76
06-06-2003, 12:30 PM
First off, try fixing your input tag:
<input type=checkbox name=Erika value=Erika<br />
ought to be
<input type=checkbox name=Erika value=Erika>Erika<br />
. . .
My apologies. all that is right in my original work. this is just a sample i am showing in order to understand for the person who reads it. so it's a typo. anyway, is there any other mistake apart from simple typos. I am looking for real solution.
Angelika
06-06-2003, 01:55 PM
try this
result.asp
<%
Set CN = server.createobject("ADODB.Connection")
CN.open "Namelist"
var_sandra = request.form("sandra")
var_erika = request.form("Erika")
sql = "select * from Name Order by Date Desc"
RS.Open Sql,CN,2,2
RS.AddNew
RS.Fields("sandra") = var_sandra
RS.Fields("Erika") = var_Erika
RS.Update
RS.close
Set RS = nothing
Set CN = nothing
%>
display.asp
<%
Set CN = server.createobject("Adodb.Connection")
CN.Open "Namelist"
sql = "select * from Name Order by Date Desc"
Set RS = server.createobject("Adodb.Recordset")
RS.Open Sql,CN
Do While not record.EOF
var_Sandra=RS("Sandra")
var_Erika=RS("Erika")
Response.write"<b>Sandra:</b>" & var_Sandra & "<br />"
Response.write"<b>Erika:</b>" & var_Erika & "<br />"
RS.Movenext
Loop
RS.Close
Set RS = nothing
CN.Close
Set CN = nothing
%>
Thanks, Angelika.
I got my code working finally. I have one more request. Is there any other way to display namelist that is to reformat. Right now, I have it display like :
Sandra: Sandra
Erika : Erika
I want them to display like:
Sandra
Erika.
I tried changing the syntax and it is not working properly, getting an error.
Angelika
06-09-2003, 08:18 PM
Response.write var_Sandra & "<br />"
Response.write var_Erika & "<br />"
I tried and for some reason it wasn't displaying any names or was it giving any error messages. so I tried to change the coding as follows and it worked:
response.write RS("Sandra").value & "<br />"
Thanks for your generous help.
Angelika
06-10-2003, 10:35 AM
var_Sandra=RS("Sandra")
response.write var_Sandra & "<br />"
OR
response.write RS("Sandra") & "<br />"
I took out the .value . Thanks.
Hi..
I have one more problem to my display page. I have 67 names in the name list which pulls from the database. My problem is the names are not displaying as I want them to. For example"
Just say this is the input page with checkboxes.
Sandra
Erika
Jose
Laura
Sarah
and I have inputed Sandra and Sarah and want them to display in the display page, it displays like as follows:
Sandra
Sarah
But I want them to display one after another such as:
Sandra
Sarah
Is there a way to do that.
Angelika
06-11-2003, 11:27 AM
<%
try this:
'SQL statement
Do While not record.EOF
var_sandra=RS("Sandra")
If not If IsNull(var_sandra) Or Not var_sandra="" Then
response.write RS("Sandra") & "<BR />"
End If
var_erika=RS("Erika")
If not If IsNull(var_erika) Or Not var_erika="" Then
response.write RS("Erika") & "<BR />"
End If
var_Jose=RS("Jose")
If not If IsNull(var_Jose) Or Not var_Jose="" Then
response.write RS("Jose") & "<BR />"
End I
var_Laura=RS("Laura")
If not If IsNull(var_Laura) Or Not var_Laura="" Then
response.write RS("Laura") & "<BR />"
End I
var_Sarah=RS("Sarah")
If not If IsNull(var_Sarah) Or Not var_Sarah="" Then
response.write RS("Sarah") & "<BR />"
End I
RS.Movenext
Loop
RS.Close
Set RS = nothing
CN.Close
Set CN = nothing
nothing
Is it different field for each name?
If Not, Then
'SQL statement
Do While not record.EOF
var_name=RS("name")
If not If IsNull(var_name) Or Not var_name="" Then
response.write RS("name") & "<BR />"
End if
RS.Movenext
Loop
%>
Hi..
Yes, different field for each name. I thought about the second suggestion but was wondering how to implement because I have given name=each name/field.
I will try your first suggestion. Thanks.
It didn't help. First I got an error for the If not If ISNULL, so I took out the second If, then it worked but still is giving space. I included the If not ISNULL statement to response.write, since var_sandra = RS("Sandra") is already declared in result.asp.
Do while not RS.EOF
If not ISNULL(var_Sandra) or Not var_Sandra="" Then
Response.write RS("Sandra")& "<br />"
End If
If not ISNULL(var_Erika) or Not var_Erika="" Then
Response.write RS("Erika")& "<br />"
End If
RS.movenext
loop
RS.close
SET RS = nothing
CN.Close
Set CN = nothing
Angelika
06-11-2003, 02:23 PM
Sorry, second IF is my mistake.
So, do You still is giving space?
Let me check on my test page!
That's okay. I appreciate you help. still giving the space. anyother way.
Hi ,
I checked multiple times and there are no errors and still giving the spaces. I really need to work out with spaces. any help would be greatly appreciated.
Angelika
06-12-2003, 10:17 AM
Try this:
<%
response.write "<table border='0' cellpadding='0' cellspacing='0' width='100%'>"
Do while not RS.EOF
If Not var_Sandra="" Then
response.write "<tr>"
response.write "<td width='100%'>" & RS("Sandra") & "</td>"
response.write "</tr>"
End If
If Not var_Erika="" Then
response.write "<tr>"
response.write "<td width='100%'>" & RS("Erika") & "</td>"
response.write "</tr>"
End If
RS.movenext
loop
RS.close
response.write "</table>"
SET RS = nothing
CN.Close
Set CN = nothing
%>
Hi Angelika..
I am sorry to disturb you but this coding didn't give any result at all. It is not retreiving the info from the database, in other words the display page is empty. I worked all morning, rewriting the code and fixing the errors but of no use. I am really fed up with this piece of work but have no choice, have to roll on to prod. any help pleaseeeeeeee.
Angelika
06-12-2003, 01:07 PM
It's works on my test page.
Try again:
<%
response.write "<table border='0' cellpadding='0' cellspacing='0' width='100%'>"
Do while not RS.EOF
If Not RS("Sandra")="" Then
response.write "<tr>"
response.write "<td width='100%'>" & RS("Sandra") & "</td>"
response.write "</tr>"
End If
If Not RS("Erika")="" Then
response.write "<tr>"
response.write "<td width='100%'>" & RS("Erika") & "</td>"
response.write "</tr>"
End If
RS.movenext
loop
RS.close
response.write "</table>"
SET RS = nothing
CN.Close
Set CN = nothing
%>
Angelika,
Hooray!!! Finally I got the last coding working. Thank you so much. I will not forget this generous help.
derick_loo
07-06-2003, 10:39 PM
Sorry, may i know how u use a check box and insert a data into database. example like your, sandra and erika. when user check erika and click submit button. the word erika will insert inot database and show erika in the database. can show me how u do that?? pls. is urgent.
Thanks a lot
Angelika
07-07-2003, 04:46 PM
OK!
1st page:
<form method="POST" action="page2.asp">
<p><input type="checkbox" name="checkbox1" value="ON"></p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>
2nd page:
<%
var_Erika=request.form("checkbox1")
IF not var_Erika="" then
sql = "select * from table_name"
RS.Open Sql,CN,3,3
RS.AddNew
RS("Erika") = var_Erika
RS.Update
RS.close
End If
%>
derick_loo
07-07-2003, 08:30 PM
Thanks a lot, ifinally i got the code working already
vBulletin v3.0.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.