|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
if, then & else
I receive the following message error:
Microsoft VBScript compilation error '800a03f6' Expected 'End' /panteismo/pollwrite.asp, line 99 else ^ Can someone help me? The file's code is: <% u_input=request.form("u_input") u_ip=request.servervariables("remote_addr") if u_input = "" then response.redirect "poll.html" else accessdb="/panteismo/db/poll.mdb" cn="driver={Microsoft Access Driver (*.mdb)};" cn=cn & "dbq=" & server.mappath(accessdb) set rs = server.createobject("ADODB.Recordset") sql = "select ip from votos where ip ='" & u_ip & "'" rs.Open sql, cn if rs.eof then if u_input = "01" then sql = "insert into votos (ip, selection01) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "02" then sql = "insert into votos (ip, selection02) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "03" then sql = "insert into votos (ip, selection03) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "04" then sql = "insert into votos (ip, selection04) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "05" then sql = "insert into votos (ip, selection05) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "06" then sql = "insert into votos (ip, selection06) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "07" then sql = "insert into votos (ip, selection07) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "08" then sql = "insert into votos (ip, selection08) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "09" then sql = "insert into votos (ip, selection09) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "10" then sql = "insert into votos (ip, selection10) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "11" then sql = "insert into votos (ip, selection11) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "12" then sql = "insert into votos (ip, selection12) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "13" then sql = "insert into votos (ip, selection13) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "14" then sql = "insert into votos (ip, selection14) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "15" then sql = "insert into votos (ip, selection15) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "16" then sql = "insert into votos (ip, selection16) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "17" then sql = "insert into votos (ip, selection17) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "18" then sql = "insert into votos (ip, selection18) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "19" then sql = "insert into votos (ip, selection19) " sql = sql & "values ('" & u_ip & "',1)" else if u_input = "20" then sql = "insert into votos (ip, selection20) " sql = sql & "values ('" & u_ip & "',1)" rs.Open sql, cn response.redirect "pollresults.asp" End if else response.redirect "polloff.html" end if%> Many thanks Luis |
|
#2
|
|||
|
|||
|
Count up your "If ..." statements and you "end if" statements, the counts need to match. It's easier to see if you indent. You can use [ code ] or [ php ] forum tags to preserve formatting in your posts here, see the faq.
|
|
#3
|
|||
|
|||
|
I think my problem is to balance the if's.
I start with: if u_input = "" then response.redirect "poll.html" else In this first else, I ask the server to check the ip in a database and if the is is clear than I use 20 if condition (one for each possibility of input) and then redirect the user to pollresults.asp I close that condition with a End If. Is the ip is already in the database, i wish to redirect it to pollonce.asp I think that last condition is coliding with the first else... |
|
#4
|
|||
|
|||
|
If I were you I'd use a case statement here instead
M3ckon |
|
#5
|
|||
|
|||
|
since you are using "ELSE" to control it and and value is fixed from 1 to 20, How about using a For Loop instead?
Code:
For i=1 To 20
If u_input = i Then
sql = "insert into votos (ip, selection" & i & ") "
sql = sql & "values ('" & u_ip & "',1)"
End If
Next
Please advise if there's any errors above. Thanks. Another alternative is to use CASE statement |
|
#6
|
|||
|
|||
|
Hi m3ckon and fused,
First of all thank you for your help! ![]() A friend already told me about case statement but I don´t know who it work. I've tried to find something in the internet but without results... About the code sample you've write, fused, i´m going to try it and then i'll teel you the result... At least, it seems easier that the way I was doing...Luis |
|
#7
|
|||
|
|||
|
fused's approach is probably the best way to go, but so you know a case statement would be like so:
Code:
Select Case u_input
Case "01"
sql = "insert into votos (ip, selection01) "
sql = sql & "values ('" & u_ip & "',1)"
Case "02"
sql = "insert into votos (ip, selection02) "
sql = sql & "values ('" & u_ip & "',1)"
' ...And So On And So On
End Select
|
|
#8
|
|||
|
|||
|
Thank you for the help in the case statement... I've tried it... I don´t receive any error, but it doesn't record any vote... Any sugestion? If you want to see the page online the url is: www32.brinkster.com/panteismo/poll.html
<% u_input=request.form("u_input") u_ip=request.servervariables("remote_addr") accessdb="/panteismo/db/poll.mdb" cn="driver={Microsoft Access Driver (*.mdb)};" cn=cn & "dbq=" & server.mappath(accessdb) set rs = server.createobject("ADODB.Recordset") sql = "select ip from votos where ip ='" & u_ip & "'" rs.Open sql, cn if rs.eof then Select Case u_input Case "1" sql = "insert into votos (ip, selection1) " sql = sql & "values ('" & u_ip & "',1)" (...) Case "20" sql = "insert into votos (ip, selection20) " sql = sql & "values ('" & u_ip & "',1)" End Select response.redirect "pollresults.asp" else response.redirect "pollonce.asp" end if %> |
|
#9
|
|||
|
|||
|
From this example you're not actually executing the SQL, just assigning the statement to a SQL variable
before response.redirect "pollresults.asp" Add the lines rs.close rs.Open sql, cn,2,3 And this should work M3ckon |
|
#10
|
|||
|
|||
|
It worked
The poll is working fine!!! Thank you very to all who helped me!Luís (aka Storm) |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > if, then & else |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|