469,362 Members | 2,441 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,362 developers. It's quick & easy.

Problem with If logic ....repost

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.
Jul 22 '05 #1
7 1513
"David Shorthouse" wrote in message
news:u6**************@tk2msftngp13.phx.gbl...
: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
Jul 22 '05 #2
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
Jul 22 '05 #3
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.
Jul 22 '05 #4
Gazing into my crystal ball I observed "Roland Hall" <nobody@nowhere>
writing in news:uf**************@TK2MSFTNGP12.phx.gbl:
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.

--
Adrienne Boswell
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
Jul 22 '05 #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:u6**************@tk2msftngp13.phx.gbl...
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

Jul 22 '05 #6
"Adrienne" wrote in message
news:Xn****************************@207.115.63.158 ...
: Gazing into my crystal ball I observed "Roland Hall" <nobody@nowhere>
: writing in news:uf**************@TK2MSFTNGP12.phx.gbl:
:
: > 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
Jul 22 '05 #7
"David Shorthouse" wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
: 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
Jul 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Dave | last post: by
117 posts views Thread by Peter Olcott | last post: by
4 posts views Thread by Ben | last post: by
18 posts views Thread by jslowery | last post: by
4 posts views Thread by Earl Anderson | last post: by
reply views Thread by radhi | last post: by
11 posts views Thread by =?ISO-8859-1?Q?Jean=2DFran=E7ois_Michaud?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.