Page 1 of 1

$_POST with a variable?

Posted: Sat Apr 09, 2005 11:15 am
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++;
}

Posted: Sat Apr 09, 2005 11:44 am
by Chris Corbyn

Code: Select all

//Use this syntax instead (no quotes)
$_POST[$account];

Posted: Sat Apr 09, 2005 6:34 pm
by John Cartwright

Code: Select all

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