Results 1 to 3 of 3
  1. #1
    Join Date
    May 2003

    Unanswered: *pls help (3 day bug)* If statement not returning TRUE when it should

    I've had this bug for days now, please take a look to see if you can help. Thx

    I made an html table to store values that VBscript pulls from an Microsoft Access data base. I modified code from w3school to do this. Here's the link:
    All I change are the path, table, and field names. It works fine; It prints out the DB info in a table.

    However, when I add a simple if statement (poined out in the code below) to ensure that the only data that gets printed is that which has the same zip code as the zip code that the user entered into the html field, nothing gets printed. The if statement always evaluates FALSE, even though I've checked the 2 sides of the condition statement, and they match up. Here's the code:

    <!DOCTYPE asp>
    <% Response.Buffer = True %>

    set conn=Server.CreateObject("ADODB.Connection")
    conn.Open "C:\Inetpub\wwwroot\RH25.mdb"
    set rs = Server.CreateObject("ADODB.recordset")
    sql="SELECT zip, email, skills FROM members"
    rs.Open sql, conn
    zip = rs("zip")
    zw = request.querystring("zipWanted")
    response.write "zip= " & zip & " zw= " & zw
    <table border="1" width="100%">
    <%for each x in rs.Fields
    response.write("<th>" & & "</th>")
    <%do until rs.EOF%>
    <%for each x in rs.Fields%>
    <%if zip = zw Then <----here's the if statement
    Response.Write (x.value)
    end if%>

    Thx again.

  2. #2
    Join Date
    Feb 2002
    One thought. What data type is the "Zip" field in your table. The form will always return a string. If your Zip field is a number then they will not match.

  3. #3
    Join Date
    May 2003
    yup, that fixed it! I was thinking about trying that last night before going to bed; Your comment focused my attention to it this afternoon.

    <%if Cstr(rs("zip")) = Cstr(request.querystring("zipWanted")) Then
    Response.Write (x.value)
    end if%>

    Thanks =)

Posting Permissions

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