Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rule not being followed.. strange

Status
Not open for further replies.

vasox56

Technical User
May 8, 2007
75
GB
hi there.. im having some trouble here and i dont know why.

im using this code

Code:
<%
If zid >= "p1" and zid <= "p321" Then
%>

<p class="mainpage"><%=zpostcode%><br /></p>
<p class="mainpage">Full postcode (eg W1 5AB):</p>
<p><input style="margin-left:20px;width:85px;" type="text" class="txtbox" id="fullpostcode" name="fullpostcode" /></p><br />
<p class="mainpage">* Drop off address:</p>
<p><textarea style="margin-left:20px;width:300px;" class="long" id="dropoffaddress" name="dropoffaddress" cols="45" rows="3"></textarea></p>
<br />
<%
End If
%>

basically zid will be a number such as p1,p10,p200.. etc

the above code should display those textboxes if the p number is more then 1.. but less than 321.

so here is the first test.. for the sake of testing you can see the P number on the page and the postcode and drop off address form fields that should appear.

p3 working
http://www.londonheathrowcars.com/f...3%20-%20City,%20Bank&Pid=p3&FCar=Saloon%20car


and then for some reason, the id p4 doesnt show those fields.. illustrated here.

http://www.londonheathrowcars.com/f...0-%20City,%20Holborn&Pid=p4&FCar=Saloon%20car

does anyone know why this is happening?
 
Your not doing numeric comparison, your doing string comparison. As such, "p4" is actually greater than "p3xxx"
because the character "4" is greater than the character "3".

On the other hand, I could put in "p123456789" and that would pass because alphabetically it falls between "p1" and "p321".

Your best bet would be to not put the p on the front of the number (or strip it off) and do a numeric comparison.

Best MS KB Ever:
 
i tried something like this..

Code:
<%If CInt(mid(zid,2,len(zid))) >= 1 and zid <= 321 Then%>

but im gettin a mismatch.. as illustrated here.

http://www.londonheathrowcars.com/f...WC1%20-%20Bloomsbury&Pid=p5&FCar=Saloon%20car

at the moment i havent declared the var as any datatype.. it is just read in like so..

Code:
zid = Request.Querystring("Pid")
 
Your second comparison is still doing a string compairon (because zid is still a string). Your first comparison is probably doing an overflow because the last argument of the mid function is length not end position.

The easiest solution would be to declare a thirs variable to hold your numeric id for temporary uses and use the right() function:
Code:
Dim npid

zid = Request.Querystring("Pid")
'get the right side if the zid is more than one character
If Len(zid) > 1 Then npid = Right(zid,Len(zid)-1)
'convewrt to int if npid is numeric
If IsNumeric(npid) Then npid = cInt(npid)

You should have some error checking in there somewhere to ensure someone doesn't try to inject odd stuff in the querystring. A better solution would probably be to not put the p at the front when you pass it. Even better, you would probably be better off not passing that in the querystring.

Best MS KB Ever:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top