$_POST with a variable?

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
jbsloan
Forum Newbie
Posts: 1
Joined: Sat Apr 09, 2005 11:09 am

$_POST with a variable?

Post by jbsloan »

Is it possible to get a value from a $_POST retrieval if the name is a variable?

See code below

Code: Select all

$n=0;
while ($n < $number2){
  $Currency = mysql_result($result2, $n, "currencyname");
  $array = array($Name, $Currency);
  $Account= implode("-", $array);
  
  
  $accountval=$_POST["'$Account'"];
  echo $Account ."=". $accountval . "<BR>";
 $n++;
}
This is coming from a form that buids the input names in the same way:

Code: Select all

$n=0;
while ($n < $number2){
  $Currency = mysql_result($result2, $n, "currencyname");
  $array = array($chName, $Currency);
  $Account= implode("-", $array);
  $Accountname = "'$Account'";
  echo "<TD><INPUT name='".$Accountname."' type='text' size='8'></TD>";
 $n++;
}
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

//Use this syntax instead (no quotes)
$_POST[$account];
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$_POST["$account"];
actually, just lose the single quotes.
Post Reply