Reputation:
<?php
$var = "arbitrary";
echo <<<_END
<form method = "post" action = "feed.php">
<input type = "text" name = "$var" />
<input type = "submit" />
</form>
_END;
if (isset($_POST['$var']))
{
echo $_POST['$var'];
}
?>
I can't seem to get this $_POST data when I try to retrieve it from the variable $var. Is this possible? (Getting $_POST from something other than just a string)
Upvotes: 0
Views: 6446
Reputation: 10648
Try this:
<?php
$var = "arbitrary";
?>
<form method = "post" action = "feed.php">
<input type = "text" name = "<?php echo $var ?>" />
<input type = "submit" />
</form>
<?php
if (isset($_POST[$var]))
{
echo $_POST[$var];
}
?>
The issue was just the quoted $var
in your array syntax here $_POST['$var']
as others have mentioned. There was nothing wrong with your heredoc syntax, so if you feel more comfortable with HERDOC syntax, you should continue with it.
Upvotes: 2
Reputation: 8508
$_POST['$var']
should be $_POST[$var]
aka don't wrap your variable in a single quote
Upvotes: 6