|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
if - else if - else if - confused
Hi
I can't seem to get this working, if anyone has any idea.. I need to do the following: if str = "" or str = "" or str = "" then print this table saying - please complete form else set up the connection and retrieve all data where NI = NI or UN = UN or PW = PW OR Email = Email if no records found then user not in db so submit to db else if records found then (check individually for which record has been found) if NI = rsNI then print this table saying you are already registered else if UN = rsUN then print this table saying enter a different UN else if PW = rsPW then print this table saying enter a different PW else if Email = rsEmail then print this table saying email already in use <%end if%> <%end if%> Should I use a select case here? Confused. Thanks Lee |
|
#2
|
|||
|
|||
|
looks to me as if you are missing another End IF.
Also the 'Else if' Statement needs to be 'ElseIf' |
|
#3
|
|||
|
|||
|
Hmm, it seems overly complicated i'd agree..
Cant you just do it like this? Dim condition1,condition2,condition3 condition1 = somevalue condition2 = somevalue condition3 = somevalue If condition 1 = somevalue then do stuff you want to happen here else do stuff you want to happen if it doesn = somevalue here end if if condition2 = etc etc.. at least then you'll be sure you've got it right and then once you have, you can start playing by concatinating results (if condition1 and condition 2 or condition 3 = somevalue then blah blah) Chris |
|
#4
|
|||
|
|||
|
(incidentally it helps that if you have code that bugs, to paste it up, rather than try doing the translation into plain english and hoping for the best..)
|
|
#5
|
|||
|
|||
|
Thanks for getting back. I think someone needs to take a look at my code. The dim condition formula recommended looks interesting but I need to see a correctly written example as not sure how to write the condition??
Here's my code - hope this helps if strContractedInIndicator = "" or strFirstName = "" then %> <table> this says : please enter required text </table> <%response.end else strContractedInIndicator = "0" 'set command and establish connection Set cndb = server.CreateObject("adodb.connection") Set cmdcheckuser = server.CreateObject("adodb.command") Set cmdaddtodatabase = server.CreateObject("adodb.command") Set cmdretrievefromdb = server.CreateObject("adodb.command") Set rsrecordsretrieved = server.CreateObject("adodb.recordset") Set rscheckuser = server.CreateObject("adodb.recordset") 'set connection to local DNS or change to web host DNS cndb.CommandTimeout = 15 cndb.CursorLocation = adUseServer cndb.ConnectionString = "DSN=cjrcls" 'this is for local 'cndb.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=mydatasourcehere.mdb" on error resume next cndb.Mode = 3 '3 = adModeReadWrite cndb.open if err <> 0 then response.write "Error connecting to the database" response.end end if With cmdcheckuser .CommandTimeout = 15 set .ActiveConnection = cndb .CommandType = adCmdtext .CommandText = "SELECT * FROM ApplicantDetails WHERE NINumber = '" & strNINumber & "' OR UserName = '" & strUserName & "' OR UserPassword = '" & strUserPassword & "' OR EmailContact = '" & strEmailContact & "';" End with rscheckuser.Open cmdcheckuser,,adOpenStatic,adLockOptimistic on error resume next if err.number <> 0 then response.write "error connecting to database<br>" &_ "Error: " & err.Description response.end end if 'if can't find a record with matching NINumber then user is not in db so submit their details if rscheckuser.EOF = true or rscheckuser.BOF = true then 'pass values as parameters With cmdaddtodatabase .CommandTimeout = 15 set .ActiveConnection = cndb .CommandType = adCmdText .CommandText = "INSERT INTO ApplicantDetails (ContractedInIndicator .....This all works perfectly..passes parameters etc) on error resume next .Execute if err.number <> 0 then Response.write err.description Response.End end if 'if was successfully submitted then redirect to process page with NINumber if err.number = 0 then id = strNINumber 'added this line Response.redirect "process.asp?id=" & Encrypt(strNINumber) 'added 'Response.redirect "process.asp?id=" & strNINumber Response.End end if End with elseif rscheckuser("NINumber") = strNINumber then %> <!-- if persons NINumber has been found in db then tell them they are already registered! --> <table class="bylinefont" width="100%" bgcolor="white" border="0" cellpadding="0" cellspacing="0" align="left"> this says: you are already registered </table> <%elseif rscheckuser("UserName") = strUserName then%> <table class="bylinefont" width="100%" bgcolor="white" border="0" cellpadding="0" cellspacing="0" align="left">This says please enter a different username </table> <%elseif rscheckuser("UserPassword") = strUserPassword then %> <table class="bylinefont" width="100%" bgcolor="white" border="0" cellpadding="0" cellspacing="0" align="left">This says please enter a different password </table> <%elseif rscheckuser("EmailContact") = strEmailContact then %> <table class="bylinefont" width="100%" bgcolor="white" border="0" cellpadding="0" cellspacing="0" align="left">This says that the email is already in use </table> <%end if%> <%end if%> </body> </html> |
|
#6
|
|||
|
|||
|
ok you need a correct example?
![]() dim A, B, C A = 10 B = "blue" C = "<hr>" If A <> 10 then response.write ("I've not set A properly") else response.write("Condition A set properly") end if IF B = "blue" then response.write("Condition B set properly") else response.write("Condition B incorrectly set") endif If B = "blue" and C = "10" then response.write("Condition BC correctly set") else if A = 10 and B = "blue" then response.write("Condition AB correctly set") else response.write("HELP! IM CONFUSED HERE! BLEEP GLEE WIBBLE *DROOL*") ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > if - else if - else if - confused |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|