Problem with $_POST

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
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Problem with $_POST

Post by mattcooper »

Hi all,

I'm trying to make a dynamically generated form sticky - successful in every way, except for the textfields generated with the following code:

Code: Select all

$el_num =  $_POST['el_menu'];
	$i = 1;
	$x = 5;
		while($i <= $el_num){
		echo "External link # $i<br><input type=\"text\" name=\"el_name_$i\" value=\""; if(isset($_POST['el_name_{$i}'])){ echo $_POST['el_name_{$i}'];}else{ echo "Label"; } echo "\" onFocus=\"MM_setTextOfTextfield('el_name_{$i}','','')\"> Example: Sponsor $i&nbsp;&nbsp;<input type\"text\" name=\"el_url_$i\" value=\""; if(isset($_POST['el_url_{$i}'])){ echo $_POST['el_url_{$i}'];}else{ echo "URL"; } echo "\" onFocus=\"MM_setTextOfTextfield('el_url_{$i}','','')\"><a href=\"help.php?context=el_urls\" target=\"_blank\"><img src=\"images/help.gif\" border=\"0\"></a><br>";
		$i++;
		}
	}
}
The test always returns false and displays the defualt text for the textfields instead of the posted value. If I echo out "el_name_2" elsewhere i the page, it's fine. But when I try to do it using the "$i" variable, it doesn't work - even though "$i" is storing the numbers correctly.

Can anyone see what I've done wrong?

Thanks in advance!
Last edited by mattcooper on Mon Mar 27, 2006 12:08 pm, edited 1 time in total.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Variables can only be parsed inside double quotes...
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Post by mattcooper »

That's what I thought, but how is it then that the other aspects of this script work fine? Everything is spot-on apart from the bit in question...

What's the fix for this? Sorry, but I just can't figure it out!!

Thanks
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

It's working fine in the first string because you are parsing variables in " double quotes.

The post vars:

Code: Select all

$_POST['el_name_{$i}']
Are being parsed in single quotes...
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Post by mattcooper »

I see that... but can't figure out the fix!!

Thanks for your time...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use double quotes.

Code: Select all

$_POST["el_name_{$i}"]
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Post by mattcooper »

Thank you, Feyd. I use single quotes habitually in array parantheses, it didn't occur to me to do that! And it's only Monday... :D
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

mattcooper wrote:Thank you, Feyd. I use single quotes habitually in array parantheses, it didn't occur to me to do that! And it's only Monday... :D
:? :? :?
hawleyjr wrote:Variables can only be parsed inside double quotes...
hawleyjr wrote:It's working fine in the first string because you are parsing variables in " double quotes.

The post vars:

Code: Select all

$_POST['el_name_{$i}']
Are being parsed in single quotes...
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Post by mattcooper »

hawleyjr wrote:It's working fine in the first string because you are parsing variables in " double quotes.

The post vars:

Code: Select all

$_POST['el_name_{$i}']
Are being parsed in single quotes...
Far too cryptic for me when my head is fried at the end of a working day... sorry fella.
Post Reply