# symbol in get statement

Thread Solved

Join Date: Sep 2009
Posts: 14
Reputation: andym67 is an unknown quantity at this point 
Solved Threads: 0
andym67 andym67 is offline Offline
Newbie Poster

# symbol in get statement

 
0
  #1
Sep 30th, 2009
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:

  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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 831
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 136
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: # symbol in get statement

 
0
  #2
Sep 30th, 2009
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.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 14
Reputation: andym67 is an unknown quantity at this point 
Solved Threads: 0
andym67 andym67 is offline Offline
Newbie Poster

Re: # symbol in get statement

 
0
  #3
Sep 30th, 2009
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.!
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 14
Reputation: andym67 is an unknown quantity at this point 
Solved Threads: 0
andym67 andym67 is offline Offline
Newbie Poster

Re: # symbol in get statement

 
0
  #4
Sep 30th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: # symbol in get statement

 
0
  #5
Sep 30th, 2009
urlencode()

Look it up.
Google is your friend.

Use [code] tags.

If you have found a solution to your problem, please mark the thread as SOLVED.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 982
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 128
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

Re: # symbol in get statement

 
-1
  #6
Sep 30th, 2009
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:

  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.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count - unless you're a serial downvoter.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 14
Reputation: andym67 is an unknown quantity at this point 
Solved Threads: 0
andym67 andym67 is offline Offline
Newbie Poster

Re: # symbol in get statement

 
0
  #7
Sep 30th, 2009
Originally Posted by kkeith29 View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 14
Reputation: andym67 is an unknown quantity at this point 
Solved Threads: 0
andym67 andym67 is offline Offline
Newbie Poster

Re: # symbol in get statement

 
0
  #8
Sep 30th, 2009
Very helpful - Thanks.!!! Didn't know about urlencode()
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 43
Reputation: edwinhermann is an unknown quantity at this point 
Solved Threads: 9
edwinhermann edwinhermann is offline Offline
Light Poster

Re: # symbol in get statement

 
2
  #9
Sep 30th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 982
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 128
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

Re: # symbol in get statement

 
-1
  #10
Sep 30th, 2009
Yes, right enough, I cobbled the code from a cgi script. No need for h.e.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count - unless you're a serial downvoter.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
Reply With Quote Quick reply to this message  
Reply

Tags
#, header

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC