Help with + and & (1 Viewer)

david.brent

Registered User.
Local time
Today, 23:36
Joined
Aug 25, 2004
Messages
57
Hello everyone,

How do you all deal with + and & when sending info to an ASP?

Some of our Reference fields contain + and/or &

When the user enters a ref containing + eg SMITH+1, SMITH 1 is sent to the SQL server stored procedure.

When the user enters a ref containing & eg SMITH+1, SMITH is sent to the SQL server stored procedure.

Obviously, this isn't ideal.

I have looked at using Replace on the sending page and then on the ASP eg

Sending Page
Replace(mr,"+","***")

ASP
Replace(mr,"***","+")

I have also looked at conventing to ASCII using .charCodeAt(0)

and then reversing it with .fromCharCode(...)

Any thoughts or examples would be greatfully recieved.

Cheers
 

Keith Nichols

Registered User.
Local time
Tomorrow, 01:36
Joined
Jan 27, 2006
Messages
431
Not quite answering the question...

I'm sorry I can't help with your actual query, but the thread linked below explains the differences between + and &. Basically 1 propagates a null and the other doesn't.

Re-reading your post, I am not sure why "Smith & 1" does not end up as Smith 1 as there is no null, but the link may still be useful to you.

http://www.access-programmers.co.uk/forums/showthread.php?t=103421&highlight=trick

A thought on your actual problem, could you change the way data is input? A text box for the name and a text box formatted to numbers for the guests.

That way, you could control the concatenation between the 2 boxes prior to further processing and so end up with a consistent format of information passed on. If you went down this path, the not propagating nulls feature would be useful.

Hope this helps somewhat.

PS:
I watched re-runs of the office second series the other night and I can't get the "do doo do-do-do' Muppet theme out of my head. Thanks David! :)
 

david.brent

Registered User.
Local time
Today, 23:36
Joined
Aug 25, 2004
Messages
57
Cheers Keith,
For concatenation in Access, I always use '&'.

This issue is about getting the information from the input page (HTML) to the ASP. If the reference being searched for contains a '+', this is interpreted as a space. If the reference has a '&' in, this is interpreted as a termination eg

The URL for the ASP would be something like

.../BillSearch/BillSearch.asp?mr=Smith&1&am=119.00

This should give me a recordset of Bills with the ref Smith&1 and amount of 119.00. The recordset returned is for Smith only.

There are many ways to get around this but modifying the way the data is input or the data itself is not an option as the reference is generated by the contractor and is used in all future correspondence.

I was just wondering how other people dealt with this.

PS
I've had that muppet song going around in my head since you mentioned it. I will try an experiment in work today to see if I can get people to join in. Most of the people I work with are barely awake most of the time. We'll see.

Take care.
 

Keith Nichols

Registered User.
Local time
Tomorrow, 01:36
Joined
Jan 27, 2006
Messages
431
Hi David,

Best of luck with the Muppet theme. :)

Everything you are talking about is way beyond my experience so the following opinion is even more ill informed than usual :eek: :confused: :D

Having said that, it seems that the data comes from an HTML page somewhere and is sucked into your database, somehow processed and then regurgitated to an ASP?

Is there nowhere in that loop that you could insert some tests for '&' or '+' and deal with each situation accordingly before final processing? How about a "find and replace" hard coded?

Sorry I haven't any relevant experience to share but I will follow the thread with interest, assuming someone else posts, somehow you solve this knotty little problem.
 

Adeptus

What's this button do?
Local time
Tomorrow, 10:06
Joined
Aug 2, 2006
Messages
300
A couple of things to look at...

1. Do you have to have the search items in the URL like that?
The form's METHOD is obviously set as GET. If you set METHOD=POST then it will send "invisibly" and not have the same hassles. When receiving the data, you need to work with request.form("fieldname") instead of request.querystring("fieldname")

2. If you must use GET, try replacing the & with %26 and the + with %2B - these are the HTML character codes, it should decode them automatically at the receiving end.
 

david.brent

Registered User.
Local time
Today, 23:36
Joined
Aug 25, 2004
Messages
57
Adeptus,
Thanks for the reply. It gave me an idea to write a URLEncode type function in Javascript. I iterate through the reference and check each character to see if it's none alpha numeric (using charCodeAt) to get the chr$ value. I then convert this to Hex and bung a '%' in front.

Ref contains an &.
Dec = 38
Hex = 26
URLEncode = %26

Cheers for the advice.

Keith,
As you can see, it took your advice onboard about testing the string before posting to the ASP.

Cheers to you too.

PS Muppet theme has gone now. Trying to avoid thinking avout it. Doh M N M N
 

Keith Nichols

Registered User.
Local time
Tomorrow, 01:36
Joined
Jan 27, 2006
Messages
431
david.brent said:
Ref contains an &.
Dec = 38
Hex = 26

Dave,

I'm glad you got your problem sorted although I confess the answer doesn't mean much to me. Out of interest, does the "URLEncode = %26" configure the ampersand to be treated as text or change it to a '+'?

Regards.
 

Kodo

"The Shoe"
Local time
Today, 19:36
Joined
Jan 20, 2004
Messages
707
David.. in javascript there is an escape() function that will do this.

Also, I'm quite curious now. I've seen this thread a few times and I just keep scratching my head. A string is a string is a string. If you have form fields that contain & or +, then it is part of a string.. any form POST's to any other page should have ZERO issues. So I fail to see the problem. Can you provide further detail?
 

david.brent

Registered User.
Local time
Today, 23:36
Joined
Aug 25, 2004
Messages
57
Cheers Kodo,

I agree a string is just a string the url to the asp is something like this

...search.asp?mr=smith+1&am=1000

when I request.querystring(mr) the value I get is 'smith 1'
when I request.querystring(am) the value I get is 1000

the + is being treated like a space.

...search.asp?mr=smith&1&am=1000
when I request.querystring(mr) the value I get is 'smith'
when I request.querystring(am) the value I get is null

the & seems to terminate the url string.

Escape() is great, but it doesn't seem the encode the '+'.

I think my overall problem is that I don't specifically use POST or GET. I don't even use a FORM. I click a hypherlink when input is finished. The onclick event fires a Javascript validation function. If there's a problem with the input, I return false. If there isn't a problem, I use 'window.location.href' and the URL to the asp. So I think I get GET by default.

I've been developing this as a training tool, mostly on the SQL sever side (I'm DB admin) and because of this it has to wait until all the proper work is done. I can't even remember why I decided not to use forms. Unfortunately, someone on the business side has seen the app now and the business wants it NOW. I can stall them for a bit.

So Kodo, have I made some bad decisions (especially not using Form(s)). Any feedback/point of view would be greatly appreciated.

Thanks again.
 

Adeptus

What's this button do?
Local time
Tomorrow, 10:06
Joined
Aug 2, 2006
Messages
300
Let's see if I have this straight.
You have 2 ASP pages.
The first takes input and manually constructs a URL to the second, including querystring parameters.

I think you'll have to either replace it with a POST form, or (if you're using ASP.NET) do some more complicated stuff to read the previous page's fields.

Also, if you're using .NET you can use the built-in validation controls rather than building your own.
 

Kodo

"The Shoe"
Local time
Today, 19:36
Joined
Jan 20, 2004
Messages
707
going along with Adeptus.. these data should NOT be in the querystring.. this should be a form POST and not passed in the querystring. Datavalidation should not just be performed on the client side.. it's ok to do that but you definately NOT rely on that as Javascript can be disabled.
IF you need to construct form elements, then use hidden text boxes and populate them on your second page, then the form post will give you acess to the values of the hidden form .. or like Adeptus said..if you're using .NET, it's a piece of cake to get the previous pages form data.
 

david.brent

Registered User.
Local time
Today, 23:36
Joined
Aug 25, 2004
Messages
57
Kodo, Adeptus - Thanks guys.
I find your last posts particularly valuable.

My company is a bit slow on the uptake when it comes to development. We have a web development team for in-house applications. Sadly this team has NO web developers??? They are tinkering with .net trying to build Windows applications. So I have no-one to reference in our 100 strong IT department. Also, because I am now DB Admin, I cannot have .net on my machine or any other development tools. I have used good old notepad to create this app.

I can see the sense in what your saying (did a little reading this morning). It's good advice and I will take it on board for version 1.01. version 1.00 will be unleashed on the users next week (while I'm away on my hols). This decision has been taken by someone who hasn't even seen it yet!

Thank you and take care guys.
 

Adeptus

What's this button do?
Local time
Tomorrow, 10:06
Joined
Aug 2, 2006
Messages
300
david.brent said:
version 1.00 will be unleashed on the users next week (while I'm away on my hols). This decision has been taken by someone who hasn't even seen it yet!
Lord save us from so-called Managers! :eek:
 

Users who are viewing this thread

Top Bottom