Link to home
Start Free TrialLog in
Avatar of leeolive
leeolive

asked on

if - else - elseif - elseif - 'expected end statement' - confused

Hi

I keep getting asked for an 'expected end' statement, and have added at least 3  or 4 <%end if%> tags and it still keeps asking. This is the scenario:

1. check to see that all fields have been completed, if not then I do an html table saying 'please complete fields'.
2. else if all fields completed, then retrieve all records where ninumber is equal to retrieved ninumber or username is equal to retrieved username or password equal to retrieved password or email is equal to retrieved email
3. If no record found then go ahead and submit the data.
4. If ninumber equals retrieved ninumber then I do an html table saying 'you are already registered'.
5. If username equals retrieved username then I do an html table saying 'please enter a different username'
6. If password equals retrieved password then I do an html table saying 'please enter a different password'.
6. If email equals retrieved email then  I do an html table 'saying this email is already in use'.

Please could someone take a look at my code and see if you can spot anything? Where it says<table></table> is where I print my whole html table with a message. Thank you! Lee

'do server side validation in javascript turned off
if strContractedInIndicator = "" or strFirstName = "" or strUserName = "" or strUserPassword = "" or strEmailContact = "" 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 .....My Note: 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
Response.redirect "process.asp?id=" & Encrypt(strNINumber) 'added
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%>
<%end if%>


</body>
</html>

Avatar of AlfaNoMore
AlfaNoMore

'if was successfully submitted then redirect to process page with NINumber
if err.number = 0 then
id = strNINumber
Response.redirect "process.asp?id=" & Encrypt(strNINumber) 'added
Response.End
end if

End with

elseif rscheckuser("NINumber") = strNINumber then



That "End with" shouldn't be there!
I change things a bit and added my own way of coding but it is still your code. Try this:

<%
'do server side validation in javascript turned off
If strContractedInIndicator = "" Or strFirstName = "" Or strUserName = "" Or strUserPassword = "" Or strEmailContact = "" Then
      Response.Write("<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 .....My Note: 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
                        Response.Redirect("process.asp?id=" & Encrypt(strNINumber)) 'added
                        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>
<%
      Else
      End If
End If
%>

Brad
If you indent your "If Then...ElseIf...Else..." statements, they are easier to spot and close with End If. :o)

Brad
Also, you need to maintain your open questions and get them closed somehow:

Question History:

Questions Asked: 4
Questions Open: 3
Questions Graded: 1
Questions Deleted: 0
Last 10 Grades Given: A

Brad
You have one extra end if at the end.
remove one and it should be fine
Dharm
Also, the order of the conditional statement is important. Looking at your code, I was under the impression that you were writing an If...ElseIf...Else...End If statement. But I just saw that your intro stated an If...Else...ElseIf...End If statement. The correct syntax is If...Then...ElseIf...Else...End If.

Brad
Avatar of leeolive

ASKER

Hi

I'm sort of new here. Do I need to click on Accept after every response to my question?

There might be something in what you've said, Brad. I just don't see any other way of doing this..Here's what I want to achieve in english..

I have a form which collects user's personal details and then submits to a hidden submit page.
On the submit page I do server side validation to check that all fields have been completed (if strNINumber = "" or strUserName = ""). If one of the fields is found empty then I do an html table saying "please complete all fields".
If none of the fields are empty then I run a command to retrieve any records where
NINumber is the same
UserName is the same
Password is the same
Email is the same

Then I do the following checks
- Has a record been found with same NINumber? Then I do an html table saying "You are already registered"
- Has a record been found with same UserName? Then I do an html table saying "Please enter a different username"
- Has a record been found with same Password? Then I do an html table saying "Please enter a different password"
- Has a record been found with same Email? Then I do an html table saying "This email seems to be in use"

Else if, after doing all these checks, no matching record has been found then submit this persons details to the db.

It still keeps asking for 'expected end' or <%end if%> so don't suggest adding <%end if%> - tried it!

I have now changed my code from the first posting. Thanks for all your help with this. Lee

<%If strContractedInIndicator = "" or strFirstName = "" or strSurname = "" or strNINumber = "" or strStreetAddress  = "" or strTown = "" or strCity = "" or strCounty = "" or strPostalCode = "" or strCountry = "" or strHomePhoneContact = "" or strPermanentStreet = "" or strPermanentTown = "" or strPermanentCity  = "" or strPermanentCounty  = "" or strPermanentPostalCode = "" or strNOKName = "" or strNOKDateofBirth = "" or strEmployer = "" or strEmployersStreet = "" or strEmployersTown = "" or strEmployersCity = "" or strEmployersPostCode = "" or strAnnualSalary = "" or strUserPassword = "" or strPasswordReminder = "" or strPasswordReminderAnswer = "" then
%>
      <table class="bylinefont" width="100%" bgcolor="white" border="0" cellpadding="0" cellspacing="0" align="left">
      <tr><td>Please complete all fields</td></tr>
      </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=d:\webs/fzxxxxxx/db/mydb.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
      
End if%>

<%If 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">
                  <tr><td>You seem to already be registered</td></tr>
                  </table>
            
<%Elseif rscheckuser("UserPassword") = strUserPassword then %>

                  <table class="bylinefont" width="100%" bgcolor="white" border="0" cellpadding="0" cellspacing="0" align="left">
                  <tr><td>Please choose a different password</td></tr>
                  </table>

<%Elseif rscheckuser("EmailContact") = strEmailContact then %>

                  <table class="bylinefont" width="100%" bgcolor="white" border="0" cellpadding="0" cellspacing="0" align="left">
                  <tr><td>This email address is already in use</td></tr>
                  </table>
<%Else

      '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, Title, FirstName, Surname, MaidenName, MaritalStatus, Gender, DateofBirth, NINumber, StreetAddress, Town, City, County, PostalCode, Country, EmailContact, HomePhoneContact, MobilePhoneContact, PermanentStreet, PermanentTown, PermanentCity, PermanentCounty, PermanentPostalCode, PermanentCountry, CountryOrigin, NOKName, NOKDateofBirth, Profession, EmploymentType, Employer, EmployersStreet, EmployersTown, EmployersCity, EmployersPostCode, EmployersCountry, WorkPhoneContact, DateJoinedCompany, AnnualSalary, RetirementAge, PolicyCommencementDate, PaymentArrangement, UserName, UserPassword, PasswordReminder, PasswordReminderAnswer, ApplicationDate, ReceiveInfoByMail, ReceiveInfoByPhone, ReceiveInfoByEmail, HearAboutExpat) VALUES ('"&strContractedInIndicator&"','"&strTitle&"','"&strFirstName&"','"&strSurname&"','"&strMaidenName&"','"&strMaritalStatus&"','"&strGender&"','"&strDateofBirth&"','"&strNINumber&"','"&strStreetAddress&"','"&strTown&"','"&strCity&"','"&strCounty&"','"&strPostalCode&"','"&strCountry&"','"&strEmailContact&"','"&strHomePhoneContact&"','"&strMobilePhoneContact&"','"&strPermanentStreet&"','"&strPermanentTown&"','"&strPermanentCity&"','"&strPermanentCounty&"','"&strPermanentPostalCode&"','"&strPermanentCountry&"','"&strCountryOrigin&"','"&strNOKName&"','"&strNOKDateofBirth&"','"&strProfession&"','"&strEmploymentType&"','"&strEmployer&"','"&strEmployersStreet&"','"&strEmployersTown&"','"&strEmployersCity&"','"&strEmployersPostCode&"','"&strEmployersCountry&"','"&strWorkPhoneContact&"','"&strDateJoinedCompany&"','"&strAnnualSalary&"','"&strRetirementAge&"','"&strPolicyCommencementDate&"','"&strPaymentArrangement&"','"&strUserName&"','"&strUserPassword&"','"&strPasswordReminder&"','"&strPasswordReminderAnswer&"','"&strDateToday&"','"&strReceiveInfoByMail&"','"&strReceiveInfoByPhone&"','"&strReceiveInfoByEmail&"','"&strHearAboutExpat&"')"
            .Parameters.Append(.CreateParameter ("pContractedInIndicator", adVarChar,adParamInput,50, strContractedInIndicator))
            .Parameters.Append(.CreateParameter ("pTitle", adVarChar,adParamInput,50, strTitle))
            .Parameters.Append(.CreateParameter ("pFirstName", adVarChar,adParamInput,50, strFirstName))
            .Parameters.Append(.CreateParameter ("pSurname", adVarChar,adParamInput,50, strSurname))
            .Parameters.Append(.CreateParameter ("pMaidenName", adVarChar,adParamInput,50, strMaidenName))
            .Parameters.Append(.CreateParameter ("pMaritalStatus", adVarChar,adParamInput,50, strMaritalStatus))
            .Parameters.Append(.CreateParameter ("pGender", adVarChar,adParamInput,50, strGender))
            .Parameters.Append(.CreateParameter ("pDateofBirth", adVarChar,adParamInput,50, strDateofBirth))
            .Parameters.Append(.CreateParameter ("pNINumber", adVarChar,adParamInput,50, strNINumber))
            .Parameters.Append(.CreateParameter ("pStreetAddress", adVarChar,adParamInput,50, strStreetAddress))
            .Parameters.Append(.CreateParameter ("pTown", adVarChar,adParamInput,50, strTown))
            .Parameters.Append(.CreateParameter ("pCity", adVarChar,adParamInput,50, strCity))
            .Parameters.Append(.CreateParameter ("pCounty", adVarChar,adParamInput,50, strCounty))
            .Parameters.Append(.CreateParameter ("pPostalCode", adVarChar,adParamInput,50, strPostalCode))
            .Parameters.Append(.CreateParameter ("pCountry", adVarChar,adParamInput,50, strCountry))
            .Parameters.Append(.CreateParameter ("pEmailContact", adVarChar,adParamInput,50, strEmailContact))
            .Parameters.Append(.CreateParameter ("pHomePhoneContact", adVarChar,adParamInput,50, strHomePhoneContact))
            .Parameters.Append(.CreateParameter ("pMobilePhoneContact", adVarChar,adParamInput,50, strMobilePhoneContact))
            .Parameters.Append(.CreateParameter ("pPermanentStreet", adVarChar,adParamInput,50, strPermanentStreet))
            .Parameters.Append(.CreateParameter ("pPermanentTown", adVarChar,adParamInput,50, strPermanentTown))
            .Parameters.Append(.CreateParameter ("pPermanentCity", adVarChar,adParamInput,50, strPermanentCity))
            .Parameters.Append(.CreateParameter ("pPermanentCounty", adVarChar,adParamInput,50, strPermanentCounty))
            .Parameters.Append(.CreateParameter ("pPermanentPostalCode", adVarChar,adParamInput,50, strPermanentPostalCode))
            .Parameters.Append(.CreateParameter ("pPermanentCountry", adVarChar,adParamInput,50, strPermanentCountry))
            .Parameters.Append(.CreateParameter ("pCountryOrigin", adVarChar,adParamInput,50, strCountryOrigin))
            .Parameters.Append(.CreateParameter ("pNOKName", adVarChar,adParamInput,50, strNOKName))
            .Parameters.Append(.CreateParameter ("pNOKDateofBirth", adVarChar,adParamInput,50, strNOKDateofBirth))
            .Parameters.Append(.CreateParameter ("pProfession", adVarChar,adParamInput,50, strProfession))
            .Parameters.Append(.CreateParameter ("pEmploymentType", adVarChar,adParamInput,50, strEmploymentType))
            .Parameters.Append(.CreateParameter ("pEmployer", adVarChar,adParamInput,50, strEmployer))
            .Parameters.Append(.CreateParameter ("pEmployersStreet", adVarChar,adParamInput,50, strEmployersStreet))
            .Parameters.Append(.CreateParameter ("pEmployersTown", adVarChar,adParamInput,50, strEmployersTown))
            .Parameters.Append(.CreateParameter ("pEmployersCity", adVarChar,adParamInput,50, strEmployersCity))
            .Parameters.Append(.CreateParameter ("pEmployersPostCode", adVarChar,adParamInput,50, strEmployersPostCode))
            .Parameters.Append(.CreateParameter ("pEmployersCountry", adVarChar,adParamInput,50, strEmployersCountry))
            .Parameters.Append(.CreateParameter ("pWorkPhoneContact", adVarChar,adParamInput,50, strWorkPhoneContact))
            .Parameters.Append(.CreateParameter ("pDateJoinedCompany", adVarChar,adParamInput,50, strDateJoinedCompany))
            .Parameters.Append(.CreateParameter ("pAnnualSalary", adVarChar,adParamInput,50, strAnnualSalary))
            .Parameters.Append(.CreateParameter ("pRetirementAge", adVarChar,adParamInput,50, strRetirementAge))
            .Parameters.Append(.CreateParameter ("pPolicyCommencementDate", adVarChar,adParamInput,50, strPolicyCommencementDate))
            .Parameters.Append(.CreateParameter ("pPaymentArrangement", adVarChar,adParamInput,50, strPaymentArrangement))
            .Parameters.Append(.CreateParameter ("pUserName", adVarChar,adParamInput,50, strUserName))
            .Parameters.Append(.CreateParameter ("pUserPassword", adVarChar,adParamInput,50, strUserPassword))
            .Parameters.Append(.CreateParameter ("pPasswordReminder", adVarChar,adParamInput,50, strPasswordReminder))
            .Parameters.Append(.CreateParameter ("pPasswordReminderAnswer", adVarChar,adParamInput,50, strPasswordReminderAnswer))
            .Parameters.Append(.CreateParameter ("pDate", adVarChar,adParamInput,50, strDateToday))
            .Parameters.Append(.CreateParameter ("pReceiveInfoByMail", adVarChar,adParamInput,50, strReceiveInfoByMail))
            .Parameters.Append(.CreateParameter ("pReceiveInfoByPhone", adVarChar,adParamInput,50, strReceiveInfoByPhone))
            .Parameters.Append(.CreateParameter ("pReceiveInfoByEmail", adVarChar,adParamInput,50, strReceiveInfoByEmail))
            .Parameters.Append(.CreateParameter ("pHearAboutExpat", adVarChar,adParamInput,50, strHearAboutExpat))
      
            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
<%End if%>
<%End if%>

</body>
</html>












There are two things you can do:

If you accept ONE answer as the one that helped you, then click on the "Accept" button next to the answer that helped.
If you think MORE than one person helped you, you can split the points. Down below where you enter text, there is a link that says "Split Points". you cannot give less than 20 points I think to any one person.

Well, I still beleive your code can work, you just have to remember the order of conditional statements: If...ElseIf...Else...End If. Any of the experts here including me can help you to write the code so it is correct and valid. Just let us know...

Brad
Hi Brad or anyone else around...I am back after a 2/3 month delay on this project and now need to continue.
I still haven't managed to get this to work. I have reworked my code exactly according to what you suggested, Brad (11/06/2003) but it now seems to submit to the db regardless of whether the NINumber, email or username are in the db.
Could someone please help me with this? I am rusty as it's rare that I ever work with asp.
Thank you. Lee

<%@ Language=VBScript %>
<%option explicit%>
<%Response.Buffer=True%>
<!-- #include file = "ADOVBS.INC" -->

<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">



<head><title>Expat Financial</title></head>
<body class="smallfont">

<%

Dim variables here...

Response.Expires=0

%>

<%

'I retrieve values here..

'when have time dbl check that if turn off javascript that this still works

If strContractedInIndicator = "" or strFirstName = "" or strSurname = "" or strNINumber = "" or strStreetAddress  = "" or strTown = "" or strCity = "" or strCounty = "" or strPostalCode = "" or strCountry = "" or strHomePhoneContact = "" or strPermanentStreet = "" or strPermanentTown = "" or strPermanentCity  = "" or strPermanentCounty  = "" or strPermanentPostalCode = "" or strNOKName = "" or strNOKDateofBirth = "" or strEmployer = "" or strEmployersStreet = "" or strEmployersTown = "" or strEmployersCity = "" or strEmployersPostCode = "" or strAnnualSalary = "" or strUserPassword = "" or strPasswordReminder = "" or strPasswordReminderAnswer = "" Then
      %>
      <table class="bylinefont" width="100%" bgcolor="white" border="0" cellpadding="0" cellspacing="0" align="left">
      <tr><td>Please complete all fields</td></tr>
      </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=cjr" 'this is for local
      'cndb.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=d:\webs/fz/db/EF23903.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 = adCmdStoredProc
            .CommandText = "qCheckNIEmailUserName"
            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 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, Title, FirstName, Surname, MaidenName, MaritalStatus, Gender, DateofBirth, NINumber, StreetAddress, Town, City, County, PostalCode, Country, EmailContact, HomePhoneContact, MobilePhoneContact, PermanentStreet, PermanentTown, PermanentCity, PermanentCounty, PermanentPostalCode, PermanentCountry, CountryOrigin, NOKName, NOKDateofBirth, Profession, EmploymentType, Employer, EmployersStreet, EmployersTown, EmployersCity, EmployersPostCode, EmployersCountry, WorkPhoneContact, DateJoinedCompany, AnnualSalary, RetirementAge, PolicyCommencementDate, UserName, UserPassword, PasswordReminder, PasswordReminderAnswer, ApplicationDate, ReceiveInfoByMail, ReceiveInfoByPhone, ReceiveInfoByEmail, HearAboutExpat) VALUES ('"&strContractedInIndicator&"','"&strTitle&"','"&strFirstName&"','"&strSurname&"','"&strMaidenName&"','"&strMaritalStatus&"','"&strGender&"','"&strDateofBirth&"','"&strNINumber&"','"&strStreetAddress&"','"&strTown&"','"&strCity&"','"&strCounty&"','"&strPostalCode&"','"&strCountry&"','"&strEmailContact&"','"&strHomePhoneContact&"','"&strMobilePhoneContact&"','"&strPermanentStreet&"','"&strPermanentTown&"','"&strPermanentCity&"','"&strPermanentCounty&"','"&strPermanentPostalCode&"','"&strPermanentCountry&"','"&strCountryOrigin&"','"&strNOKName&"','"&strNOKDateofBirth&"','"&strProfession&"','"&strEmploymentType&"','"&strEmployer&"','"&strEmployersStreet&"','"&strEmployersTown&"','"&strEmployersCity&"','"&strEmployersPostCode&"','"&strEmployersCountry&"','"&strWorkPhoneContact&"','"&strDateJoinedCompany&"','"&strAnnualSalary&"','"&strRetirementAge&"','"&strPolicyCommencementDate&"','"&strUserName&"','"&strUserPassword&"','"&strPasswordReminder&"','"&strPasswordReminderAnswer&"','"&strDateToday&"','"&strReceiveInfoByMail&"','"&strReceiveInfoByPhone&"','"&strReceiveInfoByEmail&"','"&strHearAboutExpat&"')"
                  .Parameters.Append(.CreateParameter ("pContractedInIndicator", adVarChar,adParamInput,50, strContractedInIndicator))
                  .Parameters.Append(.CreateParameter ("pTitle", adVarChar,adParamInput,50, strTitle))
                  .Parameters.Append(.CreateParameter ("pFirstName", adVarChar,adParamInput,50, strFirstName))
                  .Parameters.Append(.CreateParameter ("pSurname", adVarChar,adParamInput,50, strSurname))
                  .Parameters.Append(.CreateParameter ("pMaidenName", adVarChar,adParamInput,50, strMaidenName))
                  .Parameters.Append(.CreateParameter ("pMaritalStatus", adVarChar,adParamInput,50, strMaritalStatus))
                  .Parameters.Append(.CreateParameter ("pGender", adVarChar,adParamInput,50, strGender))
                  .Parameters.Append(.CreateParameter ("pDateofBirth", adVarChar,adParamInput,50, strDateofBirth))
                  .Parameters.Append(.CreateParameter ("pNINumber", adVarChar,adParamInput,50, strNINumber))
                  .Parameters.Append(.CreateParameter ("pStreetAddress", adVarChar,adParamInput,50, strStreetAddress))
                  .Parameters.Append(.CreateParameter ("pTown", adVarChar,adParamInput,50, strTown))
                  .Parameters.Append(.CreateParameter ("pCity", adVarChar,adParamInput,50, strCity))
                  .Parameters.Append(.CreateParameter ("pCounty", adVarChar,adParamInput,50, strCounty))
                  .Parameters.Append(.CreateParameter ("pPostalCode", adVarChar,adParamInput,50, strPostalCode))
                  .Parameters.Append(.CreateParameter ("pCountry", adVarChar,adParamInput,50, strCountry))
                  .Parameters.Append(.CreateParameter ("pEmailContact", adVarChar,adParamInput,50, strEmailContact))
                  .Parameters.Append(.CreateParameter ("pHomePhoneContact", adVarChar,adParamInput,50, strHomePhoneContact))
                  .Parameters.Append(.CreateParameter ("pMobilePhoneContact", adVarChar,adParamInput,50, strMobilePhoneContact))
                  .Parameters.Append(.CreateParameter ("pPermanentStreet", adVarChar,adParamInput,50, strPermanentStreet))
                  .Parameters.Append(.CreateParameter ("pPermanentTown", adVarChar,adParamInput,50, strPermanentTown))
                  .Parameters.Append(.CreateParameter ("pPermanentCity", adVarChar,adParamInput,50, strPermanentCity))
                  .Parameters.Append(.CreateParameter ("pPermanentCounty", adVarChar,adParamInput,50, strPermanentCounty))
                  .Parameters.Append(.CreateParameter ("pPermanentPostalCode", adVarChar,adParamInput,50, strPermanentPostalCode))
                  .Parameters.Append(.CreateParameter ("pPermanentCountry", adVarChar,adParamInput,50, strPermanentCountry))
                  .Parameters.Append(.CreateParameter ("pCountryOrigin", adVarChar,adParamInput,50, strCountryOrigin))
                  .Parameters.Append(.CreateParameter ("pNOKName", adVarChar,adParamInput,50, strNOKName))
                  .Parameters.Append(.CreateParameter ("pNOKDateofBirth", adVarChar,adParamInput,50, strNOKDateofBirth))
                  .Parameters.Append(.CreateParameter ("pProfession", adVarChar,adParamInput,50, strProfession))
                  .Parameters.Append(.CreateParameter ("pEmploymentType", adVarChar,adParamInput,50, strEmploymentType))
                  .Parameters.Append(.CreateParameter ("pEmployer", adVarChar,adParamInput,50, strEmployer))
                  .Parameters.Append(.CreateParameter ("pEmployersStreet", adVarChar,adParamInput,50, strEmployersStreet))
                  .Parameters.Append(.CreateParameter ("pEmployersTown", adVarChar,adParamInput,50, strEmployersTown))
                  .Parameters.Append(.CreateParameter ("pEmployersCity", adVarChar,adParamInput,50, strEmployersCity))
                  .Parameters.Append(.CreateParameter ("pEmployersPostCode", adVarChar,adParamInput,50, strEmployersPostCode))
                  .Parameters.Append(.CreateParameter ("pEmployersCountry", adVarChar,adParamInput,50, strEmployersCountry))
                  .Parameters.Append(.CreateParameter ("pWorkPhoneContact", adVarChar,adParamInput,50, strWorkPhoneContact))
                  .Parameters.Append(.CreateParameter ("pDateJoinedCompany", adVarChar,adParamInput,50, strDateJoinedCompany))
                  .Parameters.Append(.CreateParameter ("pAnnualSalary", adVarChar,adParamInput,50, strAnnualSalary))
                  .Parameters.Append(.CreateParameter ("pRetirementAge", adVarChar,adParamInput,50, strRetirementAge))
                  .Parameters.Append(.CreateParameter ("pPolicyCommencementDate", adVarChar,adParamInput,50, strPolicyCommencementDate))
                  .Parameters.Append(.CreateParameter ("pUserName", adVarChar,adParamInput,50, strUserName))
                  .Parameters.Append(.CreateParameter ("pUserPassword", adVarChar,adParamInput,50, strUserPassword))
                  .Parameters.Append(.CreateParameter ("pPasswordReminder", adVarChar,adParamInput,50, strPasswordReminder))
                  .Parameters.Append(.CreateParameter ("pPasswordReminderAnswer", adVarChar,adParamInput,50, strPasswordReminderAnswer))
                  .Parameters.Append(.CreateParameter ("pDate", adVarChar,adParamInput,50, strDateToday))
                  .Parameters.Append(.CreateParameter ("pReceiveInfoByMail", adVarChar,adParamInput,50, strReceiveInfoByMail))
                  .Parameters.Append(.CreateParameter ("pReceiveInfoByPhone", adVarChar,adParamInput,50, strReceiveInfoByPhone))
                  .Parameters.Append(.CreateParameter ("pReceiveInfoByEmail", adVarChar,adParamInput,50, strReceiveInfoByEmail))
                  .Parameters.Append(.CreateParameter ("pHearAboutExpat", adVarChar,adParamInput,50, strHearAboutExpat))
      
                  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">
      <tr><td>You are already registered</td></tr>
      </table>

      
      
            <% ElseIf rscheckuser("EmailContact") = strEmailContact Then %>
      
                        <table class="bylinefont" width="100%" bgcolor="white" border="0" cellpadding="0" cellspacing="0" align="left">
      <tr><td>The email entered is currently in use</td></tr>
      </table>
                  
                  

            <% ElseIf rscheckuser("UserName") = strUserName Then %>
            
                        <table class="bylinefont" width="100%" bgcolor="white" border="0" cellpadding="0" cellspacing="0" align="left">
      <tr><td>The username entered is currently in use. Please use go back and enter another username.</td></tr>
      </table>
                  
      <%
      Else
      End if
End if
      %>

            
</body>
</html>

Yikes! I'm going to have to look over this again to see what the heck we were talking about. :o)

Brad
ASKER CERTIFIED SOLUTION
Avatar of Brad Dobyns, CSM
Brad Dobyns, CSM
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial