Simple ASP error...

Soldato
Joined
13 Feb 2004
Posts
2,654
Location
South Shields
Alreeet.

For some reason is always the simple things that I get errors on.. but I can plough through some of the more complex stuff..

So.. I'm having problems with an If, Then, Else statement :o

When the user inputs their forename I want the asp page to check the forename and make sure that it is only constructed with letters.. and no numbers or symbols.

Therefore I have created this code..

<%
'Open the database connection
Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Members.mdb")
%>

<%
'Add new member
sqlAddMember ="INSERT INTO Members ( `Member Salutation`, `Member Forename`, `Member Surname`, `Member Email Address`) VALUES ('" & Salutation & "', '" & Forename & "', '" & Surname & "', '" & Email & "')"

If Forename.contenttype="text" Then con.execute sqlAddMember
'Display confirmation message to the user.
Response.Write( Salutation & "&nbsp;" & Surname & " you have been successfully added to our email list")

Else Response.Write("There has been an error with your submission")

End If
%>

However it constantly shows the Salutation & "&nbsp;" & Surname & " you have been successfully added to our email list line but never actually adds the information to the database.

Any ideas.. have I missed anything obvious.

Also.. this input page works on IIS (if I comment out the If, Then, Else) and adds a user to the database. However it does not work on my ASP enabled host. Could this be a directory issue?

Thanks for looking :)
 
Soldato
Joined
18 Oct 2002
Posts
15,203
Location
The land of milk & beans
the problem is you're using the two different ways of using the if statement in one clause, and they are mutually exclusive.

basically the two ways of using an if statement are...

Code:
if [i]condition[/i] then [i]procedure_A[/i] else [i]procedure_B[/i]
Code:
if [i]condition_A[/i] then
   [i]procedure_A[/i]
(elseif [i]condition_B[/i] then
   [i]procedure_B[/i])
else
   [i]procedure_C[/i]
end if
so your code should be...

Code:
If Forename.contenttype="text" Then 
   con.execute sqlAddMember
   'Display confirmation message to the user.
   Response.Write( Salutation & "&nbsp;" & Surname & " you have been successfully added to our email list")
Else 
   Response.Write("There has been an error with your submission")
End If
HTH!
 
Associate
Joined
23 Oct 2005
Posts
201
Location
North London
sqlAddMember ="INSERT INTO Members ( `Member Salutation`, `Member Forename`, `Member Surname`, `Member Email Address`) VALUES ('" & Salutation & "', '" & Forename & "', '" & Surname & "', '" & Email & "')"

Shouldnt it be this:-

sqlAddMember ="INSERT INTO Members ([Member Salutation], [Member Forename], [Member Surname], [Member Email Address]) VALUES ('" & Salutation & "', '" & Forename & "', '" & Surname & "', '" & Email & "')"
 
Soldato
OP
Joined
13 Feb 2004
Posts
2,654
Location
South Shields
Thanks guys.. gonna try changing the code in a few mins..

@ PsychoDuck - The code works fine.. It was quite fiddly to code though..
However.. it might explain why it won't work on my web server.. so I'll give that a go too :)

Thanks again guys.. much appriciated :cool:
 
Soldato
OP
Joined
13 Feb 2004
Posts
2,654
Location
South Shields
The new code that you guys helped me with works fine.. kinda lol.

What I'm trying to achieve is a form of validation.. that brings up an error if say a numerical character is entered instead of text.
I presumed that this would be contenttype but it appears not.. as if I inputted the forename Ian then it would process the page and search for an object known as Ian.
Any help is appreciated.. I'm going to throw my head in a few boks now to try and find the answer.. :)
 
Associate
Joined
1 Jun 2006
Posts
1,378
not massively helpful i know but you should really do your validation client side

asp is very unfriendly for doing this sort of stuff.

is there a reason your not doing it that way ?

Chandler_90 said:
The new code that you guys helped me with works fine.. kinda lol.

What I'm trying to achieve is a form of validation.. that brings up an error if say a numerical character is entered instead of text.
I presumed that this would be contenttype but it appears not.. as if I inputted the forename Ian then it would process the page and search for an object known as Ian.
Any help is appreciated.. I'm going to throw my head in a few boks now to try and find the answer.. :)
 
Back
Top Bottom