Submitting Text with "&" character
Moderator: General Moderators
Submitting Text with "&" character
i find that it's hard to obtain "&" character in a submitted text
i cant obtain this by normally using $_POST nor $_GET
how can i slove it?
thx.
i cant obtain this by normally using $_POST nor $_GET
how can i slove it?
thx.
What do you see if you:
Code: Select all
<?php
echo '<pre>';
print_r($_POST);
echo '</pre>';
?>
Last edited by McGruff on Thu Aug 11, 2005 2:23 am, edited 1 time in total.
-
bionicdonkey
- Forum Contributor
- Posts: 132
- Joined: Fri Jan 31, 2003 2:28 am
- Location: Sydney, Australia
- Contact:
you'll need to use
Code: Select all
&-
Tubbietoeter
- Forum Contributor
- Posts: 149
- Joined: Fri Mar 14, 2003 2:41 am
- Location: Germany
Can we see more code? We need to see how your form is setup as well as how you handle the passed variable in your script.
I believe, however, the problem rests with your implementation. If you pass a link as http://www.none.com/test.php?name=tammy&john, the script only assigns Tammy to name, as you are seeing. This is because the Ampersand is a delimeter that says we have another variable coming your way. Therefore, john is becoming a variable.
What urlencode does is replace the ampersand (&) with a different representation of it so your URL will work properly. If these pieces of advice don't help, you NEED to post some code so we can manipulate and explain it for you.
I believe, however, the problem rests with your implementation. If you pass a link as http://www.none.com/test.php?name=tammy&john, the script only assigns Tammy to name, as you are seeing. This is because the Ampersand is a delimeter that says we have another variable coming your way. Therefore, john is becoming a variable.
What urlencode does is replace the ampersand (&) with a different representation of it so your URL will work properly. If these pieces of advice don't help, you NEED to post some code so we can manipulate and explain it for you.
here is my sample
in html:
<form action="action.php" method="post">
<input name="name" type="text">
</form>
the value in name is tammy&john
in php:
<?
echo $_POST['name']
?>
the result is tammy only
is these enough?
in html:
<form action="action.php" method="post">
<input name="name" type="text">
</form>
the value in name is tammy&john
in php:
<?
echo $_POST['name']
?>
the result is tammy only
is these enough?
Last edited by style on Wed Jul 09, 2003 9:44 am, edited 1 time in total.
That's odd. If you've got an & in a POST var it should echo out as an &. GET is a different story.
The input tag isn't closed in the posted code, you've got a brace closing the POST key rather than a square bracket, and no semi-colon to terminate the line but I assume your actual form script is working if you're getting at least half a POST var.
The input tag isn't closed in the posted code, you've got a brace closing the POST key rather than a square bracket, and no semi-colon to terminate the line but I assume your actual form script is working if you're getting at least half a POST var.
Last edited by McGruff on Wed Jul 09, 2003 8:45 am, edited 2 times in total.
style: it appears you never looked at html before.
if you did you'd know that & is a special character there and a flag that you're dealing with a new variable. therefore php stops parsing at it you cannot put it in unless via &, and even then i'm not sure that php would grab it correctly.
put a disclaimer over the text box not to use &
also go grab a html prep book. i think you might need it.
try the oreilly book webmaster in a nutshell it's a great reference book. i have edition 2 and it's still rather relevant. the isbn of the latest version is 0596003579
it strikes me that if you had a good reference book to check this issue you could clear up on your own. you learn more when you do it on your own. so that should be a worthwhile buy for you
if you did you'd know that & is a special character there and a flag that you're dealing with a new variable. therefore php stops parsing at it you cannot put it in unless via &, and even then i'm not sure that php would grab it correctly.
put a disclaimer over the text box not to use &
also go grab a html prep book. i think you might need it.
try the oreilly book webmaster in a nutshell it's a great reference book. i have edition 2 and it's still rather relevant. the isbn of the latest version is 0596003579
it strikes me that if you had a good reference book to check this issue you could clear up on your own. you learn more when you do it on your own. so that should be a worthwhile buy for you