Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - if - else - elseif - confused!
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

if - else - elseif - confused!

 Post Reply Post Reply
Author
leeolive View Drop Down
Newbie
Newbie


Joined: 05 November 2003
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote leeolive Quote  Post ReplyReply Direct Link To This Post Topic: if - else - elseif - confused!
    Posted: 05 November 2003 at 12:27pm

Hi

Can someone please help?

I keep getting an error saying 'expected end line 1508' which is at the bottom of my page.

My code is so incredible long otherwise I would post it here. Do you have any ideas?

Thanks!

if str="a" or str="b" or str="c" then
  printForm()
response.end

else
  set rs = cn.execute("select * from myTable where ni = '" & ni & "' or un = '" & un & "' or email = '" & email & "'")
  if rs.eof then
    cn.execute("INSERT myTable VALUES('" & ni & "','" & email & "'")


  else
    if rs("ni") = ni then
      print table saying you are already registered

    elseif rs("un") = un then
      print table saying username in use
    elseif rs("email") = email then
      print table saying email in use

  else
      print table saying incorrect

  end if
end if

</BODY>
</HTML>

Back to Top
PeterE View Drop Down
Newbie
Newbie
Avatar

Joined: 05 November 2003
Location: Netherlands
Status: Offline
Points: 13
Post Options Post Options   Thanks (0) Thanks(0)   Quote PeterE Quote  Post ReplyReply Direct Link To This Post Posted: 05 November 2003 at 1:44pm
Originally posted by leeolive leeolive wrote:

Hi

Can someone please help?

I keep getting an error saying 'expected end line 1508' which is at the bottom of my page.

My code is so incredible long otherwise I would post it here. Do you have any ideas?

Thanks!

if str="a" or str="b" or str="c" then
  printForm()
response.end

else
  set rs = cn.execute("select * from myTable where ni = '" & ni & "' or un = '" & un & "' or email = '" & email & "'")
  if rs.eof then
    cn.execute("INSERT myTable VALUES('" & ni & "','" & email & "'")


  else
    if rs("ni") = ni then
      print table saying you are already registered

    elseif rs("un") = un then
      print table saying username in use
    elseif rs("email") = email then
      print table saying email in use

  else
      print table saying incorrect

  end if
end if

</BODY>
</HTML>

Unless I am very mistaken this code is never going to run, first you've got the nesting of the if ... then ... elseif ... else wrong.

Second dunno what you want achieve with the commands inside the the criteria selections. dunno a better word. lol

Well if ya want to do it this way then try something like this

<%
If Str = "a" Or Str = "b" Or Str = "c" Then
    'printForm()
    response.End
Else
    Set rs = cn.execute("select * from myTable where ni = '" & ni & "' or un = '" & un & "' or email = '" & email & "'")
    If rs.EOF Then
        cn.execute ("INSERT myTable VALUES('" & ni & "','" & email & "'")
    ElseIf rs("ni") = ni Then
        'Print Table saying you are already registered
    ElseIf rs("un") = un Then
        'print table saying username in use
    ElseIf rs("email") = email Then
        'print table saying email in use
    Else
        'Print Table saying incorrect
    End If
End If
%>

commented out the strange print commands cause they would never run. You could try a response.write("blabla")

Further more creating an object for your connection and recordset would also help

If Str = "a" Or Str = "b" Or Str = "c" Then
    printForm()
    response.End
Else
    Set rs = cn.execute("select * from myTable where ni = '" & ni & "' or un = '" & un & "' or email = '" & email & "'")
    If rs.EOF Then
        cn.execute ("INSERT myTable VALUES('" & ni & "','" & email & "'")
    Else
        If rs("ni") = ni Then
             Print Table; saying; you; are; already; registered
        ElseIf rs("un") = un Then
             print table saying username in use
        ElseIf rs("email") = email Then
             print table saying email in use
        Else
             Print Table; saying; incorrect
        End If
    End If
End If

Or did you mean this.

Last but not least if your code is so long try splitting it up in logical units and include the files as you go along.

Be sure to take care of any variables if you do.

Hope this helped

 

 



Edited by PeterE
Back to Top
leeolive View Drop Down
Newbie
Newbie


Joined: 05 November 2003
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote leeolive Quote  Post ReplyReply Direct Link To This Post Posted: 05 November 2003 at 2:44pm

Thanks for getting back. In english (with a bit of code) I need to do this

'server side validation - check to see if form fields have been completed or not

if strusername = "" or strpassword = "" then

<table>I say within my html table - please complete fields!</table>

response.end ' this stop record being added if field is empty and user has to go back to form

else

'check to see if anyone is in db according to ni number. Also check to see if anyone is using the username or password. Can't have 2 people with same un and pw combination!

set up cn and run command to retrieve values where rscheckuser("ninumber") =  strninumber or rscheckuser("username") = strusername or rscheckuser("password") = strpassword or rscheckuser("Email") = stremail

if no matching value is found then

run command and submit data to db

if a matching value is retrieved then

if rscheckuser("ninumber") = strninumber then

<table>you are already registered</table>

if rscheckuser("username") = strusername then

<table>please enter a different username</table>

if rscheck("userpassword") = strpassword then

<table>please enter a different password</table>

if rscheck("email") = stremail then

<table>email already in use</table>

Surely people have come up against this? It does seem complicated but I need to do these checks and just not sure how and when to do them if I don't do them this way. I think the problem kicks in after the dat is submitted to database(if no one with same ni number found in db). Or, can I do a whole series of these instead of if then else.

if... then...end if

if...then...end if

 

Thanks for your help! Appreciate it.

Lee

 

 

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 05 November 2003 at 8:56pm

welll, looking at your first post of code...  you have three opening "if" statements and only two "end if" statements....

so low and behold, the server is telling you:
"expected end line 1508"

amazing

Contribute to the working anarchy we fondly call the Internet
Back to Top
leeolive View Drop Down
Newbie
Newbie


Joined: 05 November 2003
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote leeolive Quote  Post ReplyReply Direct Link To This Post Posted: 06 November 2003 at 2:05am

That was the first thing I tried. I added one <%end if%> and it still kept asking for 'expected end' so added another and another. Still keeps asking. Can you 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

'do server side validation in javascript turned off
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 .....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>

 

Back to Top
PeterE View Drop Down
Newbie
Newbie
Avatar

Joined: 05 November 2003
Location: Netherlands
Status: Offline
Points: 13
Post Options Post Options   Thanks (0) Thanks(0)   Quote PeterE Quote  Post ReplyReply Direct Link To This Post Posted: 06 November 2003 at 3:45am

Maybe this will help, i adjusted your tabs so that you can see where the nesting end should be, dunno if the code will work but you added one end if to much anyway. here it is.

<!-- Added this Line --> <%


'do server side validation in javascript turned off
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=mydatasourceher e.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
%>

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.