views:

410

answers:

2

I am trying to do some very simple form validation checking for null or '' (empty) using a conditional, but when I submit my form with ALL BLANK FIELDS, it does the latter section of my code.

And when I fill out all of my fields it does that other part. So when they are blank, tell the user, which is the first section of the conditional, I have pasted my code below. Any suggestions on what I can do? Is it my "OR" or "AND"

if(((f_name <> null) or (f_name <> "")) or ((l_name <> null) or (l_name <> "")) or ((username <> null) or (username <> "")) or ((password <> null) or (password <> ""))) then
    'response.redirect("account_created.asp")
    response.write("You have not filled in all fields.")
else
    Set objConn = ConnectDB()
    query       = "INSERT INTO [user] (username,[password],f_name,l_name) VALUES ('"& username &"','"& password &"','"& f_name &"','"& l_name &"')"
    Set objs    = objConn.Execute(query)
    response.write(query)
    'Response.Redirect ("thankyou.asp")

end if

Thank you in advance,

Ryan

A: 
  1. you do not need all the parentheses
  2. if fname et al are the textboxes, you need fname.Text instead
Steven A. Lowe
classic asp, not asp.net...no .Text properties
John Sheehan
Thank you guys! Appreciate the help.Ryan
Coughlin
interesting that the accepted answer is downvoted; was it something i said?
Steven A. Lowe
also interesting is that i don't know why this answer was accepted!
Steven A. Lowe
A: 

In general it should be sufficient to check for empty string (such as f_name <> ""). I however usually do this with a trim and len. len(trim(f_name)) > 0. It takes care of all spaces. You should reconsider your parenthesis since they are not necessary. if len(trim(f_name)) > 0 or ... then

bjorsig