Problem with If logic ....repost

D

David Shorthouse

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
 
R

Roland Hall

in message
: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
 
C

CJM

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
 
B

Bob Barrows [MVP]

CJM said:
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
 
D

David Shorthouse

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.
 
R

Roland Hall

in message
: Gazing into my crystal ball I observed "Roland Hall" <nobody@nowhere>
: writing in :
: > 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
 
R

Roland Hall

in message
: 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ATTN: Bob Barrows 5
error handling 4
regexp problem 4
Only one table shows up with the information 2
Disappearing Column Data 3
NextRecordset 6
IF EXISTS error! (0x80040E14) 4
code execution 3

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top