SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    voodoo if statement

    I have a form that collects info about a contact and goes to a file that processes the information.

    We don't necessarily want to write the changes to the database right away though, because certain things have to be approved by someone.

    So for several fields, I have to determine if the submitted value is even different from the original value that's already in the database.

    Here's my code:

    If request("vchBusinessAddress1") <> rs("vchBusinessAddress1") Then
    Set rlCn = Server.CreateObject("ADODB.Connection")
    rlCn.Open connStr
    sqlStr = "INSERT INTO logChangeRequest(vchTableName, vchFieldName, vchOldValue, vchNewValue, intIdValue, datRequestDate, intRequestedBy) "
    sqlStr = sqlStr & "VALUES('Contacts','vchBusinessAddress1','" & REPLACE(rs("vchBusinessAddress1"),"'","''") & "','" & REPLACE(request("vchBusinessAddress1"),"'","''") & "',"
    sqlStr = sqlStr & request("intContactId") & ", getDate(), " & Session("intStaffId") & ")"
    Set rlRs = Server.CreateObject("ADODB.RecordSet")
    Set rlRs = rlCn.Execute(sqlStr)
    Set rlRs = Nothing
    rlCn.Close
    Set rlCn = Nothing
    difflg = 1
    End If

    The existing value in the database is a null and the value being submitted by the form is '5 main st' (I'm in a testing phase)

    To verify that the values are what I think they are, I'm outputting them right before the conditional:
    |<%=request("vchBusinessAddress1")%>| vs. |<%=rs("vchBusinessAddress1")%>|<br>

    The output is exactly what I expect:
    |5 main st| vs. ||

    So why is the conditional failing? What am I missing here?

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    First of all, are you sure the actual conditional is failing, and not the query?

    I.e. if you output something after the if statement itself, does it output?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did test the conditional. I added an else and output "OUT" and "IN". The ELSE is getting met for some cosmic reason.

    "5 Main St" and "" sure don't look equal to me

  4. #4
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    357
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your conditional will fail if a value is not provided so request("whatever") ends up being null. Also, look for any 'on error resume next' I seem to recall trying to use a null in such a comparison would generate a type mismatch error.

    Also, if it were me I'd copy the request data to local variables and then use the local variables in your if conditional.
    Doug G
    =====
    "If you ain't the lead dog, the view is always the same - Anon

  5. #5
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It did in fact have to do with the differences between how vb and sql server interpret nulls, strings, and numbers.

    In the end I had to ISNULL everything and cast a few things in my query forcing everything to be seen as strings as that's how vb interprets posted form data.

  6. #6
    SitePoint Enthusiast
    Join Date
    Apr 2010
    Location
    Dana Point, CA
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    They way I've worked around the IsNull issue with some of my online forms and databases is to set all char fields with a default value of ''. This way I don't have to account for Nulls, just empty strings.

  7. #7
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    357
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Another tip, the len() function doesn't error out with a type mismatch, so an if len(mystring) < 1 then will tell you a variable isn't a value.
    Doug G
    =====
    "If you ain't the lead dog, the view is always the same - Anon


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •