Problem with If logic ....repost

Discussion in 'ASP General' started by David Shorthouse, Jun 13, 2005.

  1. I am attempting to create a "new account creation" asp, but would ideally
    like the routine to check the Access db for an existing email address and
    username (called UID below). The select query called CheckAccount works as
    expected within the db as does the append query CreateAccount. However, the
    If statement below after DataConnection.CheckAccount obviously doesn't work
    because if I attempt to create an account for which either a username or
    email address already exists in the db, the DataConnection.CreateAccount
    throws up an error, which should even have taken place in the first place.
    Any ideas appreciated.

    Dave

    Here is what I have in the header. The Response.Writes are below.

    <%
    Dim p1, p2, p3, p4, p5, p6

    p1 = Request.Form("GivenName")
    p2 = Request.Form("SurName")
    p3 = Request.Form("PWD")
    p4 = Request.Form("PWD2")
    p5 = Request.Form("Email")
    p6 = Request.Form("UID")

    If LenB(Request.Form("btnAdd")) <> 0 Then

    If p3 = p4 Then
    Dim DataConnection, RecordSet, strError1, strError2, strError3
    Set DataConnection = Server.CreateObject("ADODB.Connection")
    DataConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
    Source=" & DatabasePath & ";"
    Set RecordSet = Server.CreateObject("ADODB.Recordset")
    DataConnection.CheckAccount p5, p6, RecordSet

    If Not RecordSet.EOF Then
    If RecordSet.Fields("Email") = p5 Then
    strError1 = "<FONT FACE='ARIAL' SIZE='3'><B>Sorry,
    this Email address is taken.</B></FONT>"
    Else
    strError2 = "<FONT FACE='ARIAL' SIZE='3'><B>Sorry,
    this Username is taken.</B></FONT>"
    End if
    RecordSet.Close
    Set RecordSet=Nothing
    DataConnection.Close
    Set DataConnection=Nothing
    Else
    RecordSet.Close
    Set RecordSet = Nothing
    DataConnection.CreateAccount p1, p2, p3, p5, p6
    Session("ID") = p6
    DataConnection.Close
    Set DataConnection = Nothing
    Response.Redirect "createprofile.asp"
    Response.End
    End if
    Else
    strError3 = "<FONT FACE='ARIAL' SIZE='3'><B>Sorry, your passwords
    didn't match.</B></FONT>"
    End If
    End if
    %>

    <%
    Response.Write (strError1)
    Response.Write (strError2)
    Response.Write (strError3)
    %>

    With Text form boxes named GivenName, SurName, PWD, PWD2, Email, UID where
    PWD2 doesn't have a field in the db and is merely a check for the client.

    Thanks,

    Dave

    > Recommendations:
    > 1. Better indenting so you can see where your if...else...endif blocks
    > begin
    > and end
    > 2. Use Response.Write to see what is happening.
    > 3. I see no action being taken in the event of error 1 or 2, but that
    > could
    > be because I can't follow your logic due to the lack of proper indenting.
    >
    > Bob Barrows
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >



    --
    ______________________________
    Remove "_SPAM" to reply directly.
     
    David Shorthouse, Jun 13, 2005
    #1
    1. Advertising

  2. David Shorthouse

    Roland Hall Guest

    "David Shorthouse" wrote in message
    news:...
    :I am attempting to create a "new account creation" asp, but would ideally
    : like the routine to check the Access db for an existing email address and
    : username (called UID below). The select query called CheckAccount works as
    : expected within the db as does the append query CreateAccount. However,
    the
    : If statement below after DataConnection.CheckAccount obviously doesn't
    work
    : because if I attempt to create an account for which either a username or
    : email address already exists in the db, the DataConnection.CreateAccount
    : throws up an error, which should even have taken place in the first place.
    : Any ideas appreciated.

    Hi Dave.

    : Here is what I have in the header. The Response.Writes are below.
    :
    : <%
    : Dim p1, p2, p3, p4, p5, p6
    :
    : p1 = Request.Form("GivenName")
    : p2 = Request.Form("SurName")
    : p3 = Request.Form("PWD")
    : p4 = Request.Form("PWD2")
    : p5 = Request.Form("Email")
    : p6 = Request.Form("UID")
    :
    : If LenB(Request.Form("btnAdd")) <> 0 Then
    :
    : If p3 = p4 Then
    : Dim DataConnection, RecordSet, strError1, strError2, strError3
    : Set DataConnection = Server.CreateObject("ADODB.Connection")
    : DataConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
    : Source=" & DatabasePath & ";"
    : Set RecordSet = Server.CreateObject("ADODB.Recordset")
    : DataConnection.CheckAccount p5, p6, RecordSet
    :
    : If Not RecordSet.EOF Then
    : If RecordSet.Fields("Email") = p5 Then
    : strError1 = "<FONT FACE='ARIAL' SIZE='3'><B>Sorry,
    : this Email address is taken.</B></FONT>"
    : Else
    : strError2 = "<FONT FACE='ARIAL' SIZE='3'><B>Sorry,
    : this Username is taken.</B></FONT>"
    : End if
    : RecordSet.Close
    : Set RecordSet=Nothing
    : DataConnection.Close
    : Set DataConnection=Nothing
    : Else
    : RecordSet.Close
    : Set RecordSet = Nothing
    : DataConnection.CreateAccount p1, p2, p3, p5, p6
    : Session("ID") = p6
    : DataConnection.Close
    : Set DataConnection = Nothing
    : Response.Redirect "createprofile.asp"
    : Response.End
    : End if
    : Else
    : strError3 = "<FONT FACE='ARIAL' SIZE='3'><B>Sorry, your passwords
    : didn't match.</B></FONT>"
    : End If
    : End if
    : %>
    :
    : <%
    : Response.Write (strError1)
    : Response.Write (strError2)
    : Response.Write (strError3)
    : %>
    :
    : With Text form boxes named GivenName, SurName, PWD, PWD2, Email, UID where
    : PWD2 doesn't have a field in the db and is merely a check for the client.

    So, turn it around and compare that way? if RecordSet.eof then
    Or, perhaps the cursor is at the eof. Showing the query might be needed.

    FYI... I don't see a need for strError1, etc. Just write out the error
    unless this is a cut-down version of the page and there's something between
    the two script blocks and then I would pass it to a sub.

    sub reportError(errNum)
    Response.Write "<span style=""font: bold small arial"">Sorry, "
    select case errNum
    case 1
    Response.Write "this email address is taken."
    case 2
    Response.Write "this username is taken."
    case 3
    Response.Write "you passwords do not match."
    case else
    end select
    Response.Write "</span>" & "<br />" & vbCrLf
    end sub

    So, this:
    strError1 = "<FONT FACE='ARIAL' SIZE='3'><B>Sorry, this Email address is
    taken.</B></FONT>"

    becomes this:
    reportError(1)

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Jun 14, 2005
    #2
    1. Advertising

  3. David Shorthouse

    CJM Guest

    David,

    Why call your variables P1 - P6? This is meaningless and makes it very hard
    to debug. What is wrong with sForename, sSurname etc...?

    Also, I wouldnt call your recordset 'RecordDet'. This is a reserved word,
    and if it doesnt invoke and error it really ought to... How about rsAccount
    or similar?

    Digging deeper, it appears that you might be getting something back from
    your query [thus .EOF is not True]. You might want to investigate what it is
    you are getting retruned... Try finding if you are getting values for
    rsAccount(0), rsAccount(1) etc...

    Chris
     
    CJM, Jun 14, 2005
    #3
  4. CJM wrote:
    > David,
    >
    > Why call your variables P1 - P6? This is meaningless and makes it
    > very hard to debug. What is wrong with sForename, sSurname etc...?
    >
    > Also, I wouldnt call your recordset 'RecordDet'. This is a reserved
    > word, and if it doesnt invoke and error it really ought to... How
    > about rsAccount or similar?
    >
    > Digging deeper, it appears that you might be getting something back
    > from your query [thus .EOF is not True]. You might want to
    > investigate what it is you are getting retruned... Try finding if you
    > are getting values for rsAccount(0), rsAccount(1) etc...
    >
    > Chris

    Unfortunately, with two threads going, this has become confusing. In the
    original thread, David states that he has solved his problem.

    You both have offered some good suggestions, all the same.

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Jun 14, 2005
    #4
  5. Oops. Sorry about the two posts and not replying to my own post in this
    thread. Indeed, I did solve the problem and the solution is in the previous
    thread.

    --
    ______________________________
    Remove "_SPAM" to reply directly.

    "David Shorthouse" <davidshorthouse@shaw_SPAM.ca> wrote in message
    news:...
    >I am attempting to create a "new account creation" asp, but would ideally
    >like the routine to check the Access db for an existing email address and
    >username (called UID below). The select query called CheckAccount works as
    >expected within the db as does the append query CreateAccount. However, the
    >If statement below after DataConnection.CheckAccount obviously doesn't work
    >because if I attempt to create an account for which either a username or
    >email address already exists in the db, the DataConnection.CreateAccount
    >throws up an error, which should even have taken place in the first place.
    >Any ideas appreciated.
    >
    > Dave
     
    David Shorthouse, Jun 14, 2005
    #5
  6. David Shorthouse

    Roland Hall Guest

    "Adrienne" wrote in message
    news:Xns967568C9712D3arbpenyahoocom@207.115.63.158...
    : Gazing into my crystal ball I observed "Roland Hall" <nobody@nowhere>
    : writing in news::
    :
    : > sub reportError(errNum)
    : > Response.Write "<span style=""font: bold small arial"">Sorry, "
    : > select case errNum
    : > case 1
    : > Response.Write "this email address is taken."
    : > case 2
    : > Response.Write "this username is taken."
    : > case 3
    : > Response.Write "you passwords do not match."
    : > case else
    : > end select
    : > Response.Write "</span>" & "<br />" & vbCrLf
    : > end sub
    : >
    : > So, this:
    : > strError1 = "<FONT FACE='ARIAL' SIZE='3'><B>Sorry, this Email address is
    : > taken.</B></FONT>"
    : >
    : > becomes this:
    : > reportError(1)
    : >
    :
    : Even better:
    : Response.write "<span class='error'>...</span>"
    :
    : Then define your error styling in an external sheet. Much easier to deal
    : with if you need to change that error styling later on.

    Nice catch Adrienne.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Jun 14, 2005
    #6
  7. David Shorthouse

    Roland Hall Guest

    "David Shorthouse" wrote in message
    news:%...
    : Oops. Sorry about the two posts and not replying to my own post in this
    : thread. Indeed, I did solve the problem and the solution is in the
    previous
    : thread.

    Silly me. I read the whole other post but I thought this was after you
    thought you had it working. Sorry about that. *sheepish grin*

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Jun 14, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Little Monster

    Newbie cgi problem - repost

    Little Monster, May 2, 2004, in forum: Perl
    Replies:
    3
    Views:
    616
    Little Monster
    May 6, 2004
  2. Programatix
    Replies:
    1
    Views:
    383
    Kathleen Dollard
    Jul 17, 2003
  3. Abhishek Srivastava

    [REPOST] Problem in Windows based Authentication

    Abhishek Srivastava, Feb 18, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,636
    Ken Schaefer
    Feb 18, 2004
  4. Fernando Chilvarguer

    Child window and repost problem.

    Fernando Chilvarguer, Apr 26, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    1,770
    Fernando Chilvarguer
    Apr 26, 2005
  5. spike
    Replies:
    8
    Views:
    1,476
    Steve Holden
    Feb 9, 2010
Loading...

Share This Page