If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > *pls help (3 day bug)* If statement not returning TRUE when it should

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-12-03, 03:24
corporate_targe corporate_targe is offline
Registered User
 
Join Date: May 2003
Posts: 18
*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: http://www.w3schools.com/ado/ado_display.asp.
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 %>

<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
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%">
<tr>
<%for each x in rs.Fields
response.write("<th>" & x.name & "</th>")
next%>
</tr>
<%do until rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<td>
<%if zip = zw Then <----here's the if statement
Response.Write (x.value)
end if%>
</td>
<%next
rs.MoveNext%>
</tr>
<%loop
rs.close
conn.close
%>
</table></body>
</html>

Thx again.
Reply With Quote
  #2 (permalink)  
Old 05-12-03, 11:57
Memnoch1207 Memnoch1207 is offline
Registered User
 
Join Date: Jan 2003
Location: Midwest
Posts: 138
use a where clause in your sql statement to grab only the records that match the zip code the user entered.
Code:
sql="SELECT zip, email, skills FROM members WHERE zip = " & Request.Form("zip")"
The if statement should look like this
Code:
<%if(rs("zip") = "zw") Then 
   Response.Write (x.value)
   rs.movenext
end if%>

Last edited by Memnoch1207; 05-12-03 at 12:05.
Reply With Quote
  #3 (permalink)  
Old 05-12-03, 17:16
corporate_targe corporate_targe is offline
Registered User
 
Join Date: May 2003
Posts: 18
problem solved by casting the data types in the if statement to match

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

Thanks for your support
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On