943,945 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1101
  • PHP RSS
Sep 30th, 2009
0

# symbol in get statement

Expand Post »
Hi All,

I am processing a form that includes address info. If the user fills out the form and (address2) has an apartment number that they enter like:

#1522

I have trouble later where I might contruct a link such as:

PHP Syntax (Toggle Plain Text)
  1. header("location: contact.php?address1=$address1&address2=$address2&city=$city&state=$state");

The link creates fine, but processing on the otherside where I am trying to get the data back stops after encountering the # sysmbol. The code I have to get the data from the link is:

PHP Syntax (Toggle Plain Text)
  1. if(isset($_GET["address2"])) $address2 = $_GET["address2"]; else $address2 = "";

The address2 field is empty as are all the fields that come after it in the process. Any ideas what to do to allow the # symbol?

Thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
andym67 is offline Offline
14 posts
since Sep 2009
Sep 30th, 2009
0

Re: # symbol in get statement

try using & #35 ; instead (without the spaces),

see:

http://www.ascii.cl/htmlcodes.htm
Last edited by pritaeas; Sep 30th, 2009 at 5:07 pm.
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 731
Bite my shiny metal ass!
pritaeas is offline Offline
4,177 posts
since Jul 2006
Sep 30th, 2009
0

Re: # symbol in get statement

I don't understand. The user enters the # sign into the field and my HEADER: then uses it. Is there a way to surround it with quotes etc in my code to somehow encode it or something.

I am not understanding your suggestion. Thanks.!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
andym67 is offline Offline
14 posts
since Sep 2009
Sep 30th, 2009
0

Re: # symbol in get statement

My created url looks like this:

http://www.domain.com/contact.php?ad...=123%20Main%20 Street&address2=#1522&city=chicago

As you can see, the # is probably my problem.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
andym67 is offline Offline
14 posts
since Sep 2009
Sep 30th, 2009
0

Re: # symbol in get statement

urlencode()

Look it up.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Sep 30th, 2009
-1

Re: # symbol in get statement

The text after a # in a querystring is taken to be an anchor or bookmark. You should encode the data before passing it to a querystring.

Use urlencode and htmlentities:

PHP Syntax (Toggle Plain Text)
  1. $q_string = 'address1=' . urlencode($address1) . '&address2=' . urlencode($address2) . '&city=' . urlencode($city) . '&state=' . urlencode($state);
  2. header( 'Location: contact.php?' . htmlentities($q_string));

//EDIT
sorry KK, you posted as I was typing
Last edited by ardav; Sep 30th, 2009 at 5:22 pm.
Sponsor
Featured Poster
Reputation Points: 1048
Solved Threads: 949
Sarcastic Poster
ardav is offline Offline
6,698 posts
since Oct 2006
Sep 30th, 2009
0

Re: # symbol in get statement

Click to Expand / Collapse  Quote originally posted by kkeith29 ...
urlencode()

Look it up.
I wasn't sure what I needed to look up or I would have done so. As I am very new to PHP I didn't know the urlencode() existed.

But, thank you very much as that was what I needed. It works wonderfully. I appreciate your help.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
andym67 is offline Offline
14 posts
since Sep 2009
Sep 30th, 2009
0

Re: # symbol in get statement

Very helpful - Thanks.!!! Didn't know about urlencode()
Reputation Points: 10
Solved Threads: 0
Newbie Poster
andym67 is offline Offline
14 posts
since Sep 2009
Sep 30th, 2009
2

Re: # symbol in get statement

As ardav says, you need urlencode, but you should not use htmlentities. YOu only use htmlentities when you are outputting HTML. The header is not HTML - it's part of the underlying HTTP protocol.
Reputation Points: 52
Solved Threads: 27
Junior Poster
edwinhermann is offline Offline
134 posts
since Sep 2009
Sep 30th, 2009
-1

Re: # symbol in get statement

Yes, right enough, I cobbled the code from a cgi script. No need for h.e.
Sponsor
Featured Poster
Reputation Points: 1048
Solved Threads: 949
Sarcastic Poster
ardav is offline Offline
6,698 posts
since Oct 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: random generated number integrated into a form
Next Thread in PHP Forum Timeline: Add images in the PDF file using PHP





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC