Mixed up data from $_GET [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

Mixed up data from $_GET [SOLVED]

Post by enchance »

My data is getting mixed up when I fetch it from GET. This is what I have:
1. "contact.php" contains the form. All form data is then passed to "mail.php" using POST
2. "mail.php" fixes the data then runs a simple test. If the email was successful it sends $sendername to "sent.php" using GET
3. "sent.php" recieves the file then prints $sendername out in a simple message like "Thank you $sendername" or something. View code below:

Code: Select all

<?php
//Inside "mail.php" which sends $sendername using GET after recieving it using POST
if(mail($agiemail, $subject, $message, $header))
{
	$sendername = $_POST['fName']; //fName is "John Doe" for example
	header("Location: http://mydomain.com/sent.php?sendername=$sendername ");
}
else
{
	//sent to an error message
}
?>
But this is what came out in "sent.php"

Code: Select all

//The appended URL suddenly became: http://www.mydomain.com/sent.php?sendername=John%2520Doe
  $name = $_GET['sendername'];
  echo $name //Prints out "John%20Doe" instead of "John Doe"
I wonder what happened...
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Mixed up data from $_GET

Post by superdezign »

enchance wrote:

Code: Select all

//The appended URL suddenly became: http://www.mydomain.com/sent.php?sendername=John%2520Doe
  $name = $_GET['sendername'];
  echo $name //Prints out "John%20Doe" instead of "John Doe"
It is url-encoding the url-encoded data, changing "John%20Doe" into "John%2520Doe." Do you use urlencode() or urldecode() in in your code?
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

Post by enchance »

I got it to work using rawurldecode(). Thanks a lot for replying!
Post Reply