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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"#" sign problem - Please help

Status
Not open for further replies.

IEAN

Programmer
Sep 13, 2003
122
US
Hi all,

I have a form that will let my customer enter their billing address, but whenever a customer enter anything with the "#" sign in the street address field such as Apartment #302, my script will throw a "Datatype mismatched" error, how do I fix this problem yet still keeping the original address, # signs and all, intact?

Thank you in advance for your help!
 
can you show us your code...

Use Server.HTMLEncode(yourfield)

-DNG
 
Hi DNG, thank you for your prompt reply, I definitely would if I could, but my company simply won't allow that since those are codes at the checkout process, I hope you understand and still can help me, I tried the HTML Encode but it is still showing the error, probably because the character is # instead of " & < >...Please help, many thanks again!
 
ok, no problem, i thought you cud just show us some sample code and not the exact one...

anyways lets try some more ways to solve it...

use ASCII code for # sign ( i think it is chr(35) )

the problem here is # acts as the delimiters for dates...so thats the reason i think you are data type mismatach error...

anyways try chr(35)

also what is the datatype for your address field...

-DNG
 
DNG, the datatype for my address field is text. Actually the page that is having problem isn't doing any database action at all, all it does is do some calculations based on the "state" field passed from the previous page, then transfer the info to the next page. The address field does not have anything to do with the calculation, it is only getting tranfered.....I just don't get what is going on, I tried replacing the # with chr(35) but it is still throwing the same error...so weird...Please help!
 
but at what stage in the code you get this error...are you doing anything with address at all or not...are you assigning something to it...

put response.write statements to see what is getting printed...

show some sample code at which you are getting error...

-DNG
 
ok one more suggestion...just remove the # symbol and see if the code works...just one test scenario...

as i said i can understand that you cannot post your code...but cant you come up with something similar sample code or similar logic with some simple code just to replicate the error...

and if you can come up with the sample code that produces same error then you can post it here...

-DNG
 
Just trying to replicate the problem for the fun of it. Doesn't seem to have any problem with the #. It sends it as %23.

The body of the input form (echo.asp). I'm just using get so I can see what it is sending.
Code:
<form method="GET" action="echores.asp">
  <p>Address <input type="text" name="Addr" size="32" value="<%Request("Addr")%>">
  <input type="submit" value="Submit" name="B1">
  <input type="reset" value="Reset" name="B2"></p>
</form>

The body of the result (echores.asp)
Code:
<%
dim addr
addr = Request ("Addr")
response.write addr
%>

 
i thought so...but IEAN has to do some debugging to see whats that causing that error...

Just try putting Response.Write statements at all suspicious steps and post back your findings...

-DNG
 
Hey DNG, thanks to your help I finally found the culprit, it is the problem of another "swap" page that is causing this weird problem, now all I need to do is to do a replace func then the problem will be fixed, but I can't get the chr(35) to work in the replace statement. I have tried <%=chr(35)%> in the replace statement also but it just wouldn't work, please advise:

varAddress=replace((""& varGetAddress &""),"#","<%=chr(35)%>")

Thank you so much DNG, I couldn't have done this without your help!
 
you should just do:

varAddress=replace(varGetAddress,"#","chr(35)")

-DNG
 
Hi DNG, sorry for the delay in replying, I didn't get a chance to work on this till today, when I try varAddress=replace(varGetAddress,"#","chr(35)")
Instead of replacing # with #, it replaced # with the words chr(35).....Any ideas?
 
I think the problem is...when the page that is suppose to pass this info to another page for example:

Thispage.asp?varName="Name"&varAddress="Apartment #129"&varCity="LA"&varState="California"

When this string gets passed to the next page, the string willget cut off at #129 and on....

Since the next page calculate tax based on the "City field", if the city field is empty and the page cannot do any calculations, it throws the datatype mismatched error.

So my question is, how to have the string not cut off at the # sign?

Please advise, thanks!
 
No problem now, I worked around it, but if someone knows the solution on how to not have the string cut off at the # sign, I would still like to know just in case in the future I need to fix something like that. Thanks!
 
oops...sorry...i meant...

varAddress=replace(varGetAddress,"#",[red]chr(35)[/red])

without quotes...glad you got it working...

-DNG
 
How about filtering out the pound sign, getting rid of it completely? After all, Apartment #302 and Apartment 302 really mean the same thing.

Lee
 
Another option would be to use Server.URLEncode to make the field safe (you could just as easily replace with %23(?) to make it URL safe, but this will cover other characters as well).

If the cutoff was not the error, then I would suggest looking for any conversion functions (explicit or implicit) that might be acting on that value. The error above is usually a sign that you either tried to convert a value to a type it cannot be converted to (like a number) or that you attempted to convert (implicitly) a later field that wasn't populated (due to the cutoff problem). Generally if a field is not populated form a form it can be converted into just about anything, since VBScript is not strongly typed.

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top