Using a variable in retrieving $_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
charlie12345
Forum Newbie
Posts: 14
Joined: Wed Nov 09, 2005 5:35 am

Using a variable in retrieving $_POST

Post by charlie12345 »

Being comletely new to PHP, I don't understand why/how these two lines are different:

Code: Select all

$item=1;
 
$merchant_product_id[$item] = $_POST["merchant_product_id1"];     #this has a value 
 
$merchant_product_id[$item] = $_POST["$merchant_product_id".$item];    #this has no value
It's obvious I'm missing something somewhere...

Charlie
User avatar
sergio-pro
Forum Commoner
Posts: 88
Joined: Sat Dec 27, 2008 12:26 pm

Re: Using a variable in retrieving $_POST

Post by sergio-pro »

the second line contains $ in $merchant_product_id - and it shouldnt
charlie12345
Forum Newbie
Posts: 14
Joined: Wed Nov 09, 2005 5:35 am

Re: Using a variable in retrieving $_POST

Post by charlie12345 »

It surely does, doesn't it.

Thanks.
Charlie
tanmay
Forum Newbie
Posts: 12
Joined: Mon Jan 19, 2009 9:51 am

Re: Using a variable in retrieving $_POST

Post by tanmay »

hi charlie, as being a fresher in php, i would like to tell you that when you are receiving value in $_POST you have to pass a variable.

that you have passed in first statement, that is $_POST["$mkmk_jk"] something like that. and in second statmnt you are passing $_POST["something".$item]. make sure dat its a variable...
Post Reply