|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
posting to 2 db's
I have a service request form in asp, which takes a bunch of data (name, id, etc). it then has 2 checkboxes, either or both of which can be checked to request a certain service. depending on which box is checked, the other data collected is inserted into a corresponding database. what is the best way to do this?
can i just use 2 IF statements (not nested) to open the connections to the databases? |
|
#2
|
|||
|
|||
|
IF statements would be the easiest.
You'd probably need three statements though, 1 for checkbox1 checked 1 for checkbox2 checked 1 for both checked
__________________
How can I soar like an eagle when I'm flying with turkey's? |
|
#3
|
|||
|
|||
|
I'd use an if statement to test the values and then do some stuff based on the value...
Code:
<%
' grab all your form values...
myFormValue1 = request.form("FormValue1")
myFormValue2 = request.form("FormValue2")
checkbox1Value = request.form("checkbox1")
checkbox2Value = request.form("checkbox2")
'build your SQL satetement...
SQL1 = "some sql statement based on what you want to do if checkbox1Value = true"
SQL2 = "some sql statement based on what you want to do if checkbox2Value = true"
'conditionally execute your SQL statement...
if checkbox1Value = "checked" then
'open data base connection #1 and do your stuff..
set cn1 = server.createObject("adodb.connection")
cn1.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\yourDatabase1.mdb")
execute SQL1
elseif checkbox2Value = "checked" then
'open data base connection #2 and do your stuff..
set cn2 = server.createObject("adodb.connection")
cn2.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\yourDatabase2.mdb")
execute SQL1
end if
%>
Hope this helps, Jb. |
|
#4
|
||||
|
||||
|
it looks promising, but what is the value of the
("FormValue1") and ("FormValue2") parts? that is, what do i put in there, and why? |
|
#5
|
|||
|
|||
|
Tell me if you've heard this one before
...I handle forms by separating the 'form display' scripts from the 'form processing' scripts, that is, I display the form using one file (let's call it "index.asp") and I use a different file to handle the form processing (let's call it "act_index.asp"). In index.asp I'd have something like this... Code:
<form action="act_index.asp" method="post"> Name: <input type="text" name="FormValue1" maxlength="40"><br> ID : <input type="text" name="FormValue2" maxlength="40"><br> Which service do you want?<br> <input type="checkbox" name="checkbox1" value="checked"> Service A<br> <input type="checkbox" name="checkbox2" value="checked"> Service B<br> <input type="submit" name="submit" value="submit request"> </form> then in the act_index.asp file I'd have the form processing stuff... Code:
<%
' grab all your form values...
myFormValue1 = request.form("FormValue1")
myFormValue2 = request.form("FormValue2")
checkbox1Value = request.form("checkbox1")
checkbox2Value = request.form("checkbox2")
'build your SQL satetement...
SQL1 = "some sql statement based on what you want to do if checkbox1Value = true"
SQL2 = "some sql statement based on what you want to do if checkbox2Value = true"
'conditionally execute your SQL statement...
if checkbox1Value = "checked" then
'open data base connection #1 and do your stuff..
set cn1 = server.createObject("adodb.connection")
cn1.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\yourDatabase1.mdb")
execute SQL1
elseif checkbox2Value = "checked" then
'open data base connection #2 and do your stuff..
set cn2 = server.createObject("adodb.connection")
cn2.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\yourDatabase2.mdb")
execute SQL2
end if
%>
|
|
#6
|
||||
|
||||
|
ah, i do it the same way. just didn't quite put 2 & 2 together there. i was too focused on just the checkbox part. thanks for clarifying
|
|
#7
|
||||
|
||||
|
Thanks
thanks a bunch spincycler. your comments to this question and my related "if" statement question really helped me figure this out and solve my problem
![]() |
|
#8
|
|||
|
|||
|
just looking at my code I think I see a bug..
you may need to have two separate 'if' statements. (without testing the code) I think the way elseif's work is, if the first expression returns 'true' then the second expression will never be evaluated. Iteration #2: Code:
if checkbox1Value = "checked" then
'open data base connection #1 and do your stuff..
set cn1 = server.createObject("adodb.connection")
cn1.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\yourDatabase1.mdb")
execute SQL1
end if
if checkbox2Value = "checked" then
'open data base connection #2 and do your stuff..
set cn2 = server.createObject("adodb.connection")
cn2.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\yourDatabase2.mdb")
execute SQL2
end if
|
|
#9
|
||||
|
||||
|
that was indeed the case. 2 if statements were needed.
|
|
#10
|
|||
|
|||
|
as you rightly pointed out in your anser to my
array/checkbox question.. ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > posting to 2 db's |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|