473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ampersands in URL string

I'm having some trouble echoing string data that contains an ampersand
in it.

I am filling a WHERE clause in my SQL query with a string based upon a
choice made in a select/option form element via GET.

My request for
http://www.example.com/update_company.php?company=Bill%20&%20John's%20Cri tter%20Control%20Company

returns only Bill

Any suggestions?

--
------------------------------------
Gene Kelley
Senior Open Source Software Engineer
Advanced Design Solutions Team
Network Solutions (MonsterCommerce)
Swansea, Illinois, USA
Jun 2 '08 #1
7 2932
Gene Kelley wrote:
I'm having some trouble echoing string data that contains an ampersand
in it.
[...]
Any suggestions?
Are you urlencode()'ing your URLs?

How are you grabbing the data from the URL?

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Proudly running Debian Linux with 2.6.24-1-amd64 kernel, KDE 3.5.9, and PHP
5.2.5-3 generating this signature.
Uptime: 00:18:34 up 8 days, 3:38, 2 users, load average: 1.13, 1.20, 0.71

Jun 2 '08 #2
Gene Kelley wrote:
I'm having some trouble echoing string data that contains an ampersand
in it.

I am filling a WHERE clause in my SQL query with a string based upon a
choice made in a select/option form element via GET.

My request for
http://www.example.com/update_company.php?company=Bill%20&%20John's%20Cri tter%20Control%20Company
returns only Bill

Any suggestions?
An ampersand in the query string means end the current variable and
start a new one. Standard HTML.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #3
Jerry Stuckle wrote:
>
An ampersand in the query string means end the current variable and
start a new one. Standard HTML.
Thanks Jerry.

I will try to find a PHP function to handle the url encoding properly.

I would find it hard to believe that PHP couldn't pull a string from a
database that contained an ampersand in it.

--
------------------------------------
Gene Kelley
Senior Open Source Software Engineer
Advanced Design Solutions Team
Network Solutions (MonsterCommerce)
Swansea, Illinois, USA
Jun 2 '08 #4
Gene Kelley wrote:
Jerry Stuckle wrote:
>>
An ampersand in the query string means end the current variable and
start a new one. Standard HTML.

Thanks Jerry.

I will try to find a PHP function to handle the url encoding properly.

I would find it hard to believe that PHP couldn't pull a string from a
database that contained an ampersand in it.
There's no problem pulling it from the database. Your problem that's
how HTML works.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #5
Jerry Stuckle wrote:
>
There's no problem pulling it from the database. Your problem that's
how HTML works.
.... and in the end. The solution for me was str_replace() :-)

For my particular situation it was easiest to simply not allow &s in the
database.

--
------------------------------------
Gene Kelley
Senior Open Source Software Engineer
Advanced Design Solutions Team
Network Solutions (MonsterCommerce)
Swansea, Illinois, USA
Jun 2 '08 #6
Gene Kelley wrote:
Jerry Stuckle wrote:
>>
There's no problem pulling it from the database. Your problem that's
how HTML works.

... and in the end. The solution for me was str_replace() :-)

For my particular situation it was easiest to simply not allow &s in the
database.
As I said - there is no problem with ampersands in the database. All
you need to do is urlencode() the string before attaching it to the url
- which you should be doing, anyway. str_replace() is not required.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #7
Jerry Stuckle wrote:
Gene Kelley wrote:
>Jerry Stuckle wrote:

As I said - there is no problem with ampersands in the database. All
you need to do is urlencode() the string before attaching it to the url
- which you should be doing, anyway. str_replace() is not required.

I will do that. Thanks for the help Jerry.

--
------------------------------------
Gene Kelley
Senior Open Source Software Engineer
Advanced Design Solutions Team
Network Solutions (MonsterCommerce)
Swansea, Illinois, USA
Jun 2 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: leegold2 | last post by:
If I try to query ie. search via PHP/MYSQL my db for this string: foo&bar It will not find the string with either FullText or a sub-string search (ie. %NA&SD% ). I think the ampersand is...
1
by: leegold2 | last post by:
The subject title is a sedgeway into my question that may slightly of topic but I've asked many sources and don't have an answer yet so I ask it here. I have a text fields of html marked up...
2
by: micha | last post by:
my php script gets delivered text that contains special chars (like german umlauts), and these chars may, may partially or may not be coverted into html entities already. i don't know beforhand. ...
5
by: kaeli | last post by:
Hey all, In trying to get my site to validate (html 4.01 transitional), I ran across an issue with this type of url in an href: http://www.server.com/somePage?param1=1&param2=2 etc Notably:...
1
by: jjbutera | last post by:
How do I escape these? The backslash doesn't seem to be working.
5
by: AJ Brown | last post by:
How does one allow the use of ampersands (or other special characters for that matter) within Element text and Attribute text? I have problems using LoadXml from a string "<text value="Jack &...
4
by: MLH | last post by:
I have tried the following in the immediate window. It yields an error... ?"Hello"&vbCrLf&"there"&vbCrLf&"next"&vbCrLf&"line." 'Type declaration character does not match declared data type. ...
13
by: darrel | last post by:
I am creating a querystring to look like this: form_edit.aspx?collectionID=25&amp;confirmationMessage=New+form+entry+saved Note that I'm escaping the ampersand. However, I can't grab the...
11
by: Steven D'Aprano | last post by:
I'm using urllib.urlretrieve() to download HTML pages, and I've hit a snag with URLs containing ampersands: http://www.example.com/parrot.php?x=1&y=2 Somewhere in the process, urls like the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.