MattKnowles
MattKnowles

Reputation: 11

php $_POST variable variables

I am trying to populate an HTML form with values from a previous form being posted. The first form is created dynamically and is a list of t-shirt styles with 5 different sizes available.

I'm having trouble figuring out a way to populate the second form.

The HTML is this:

echo '<input name="'.$filename.'-s" type="text" size="3" value="'.$quantity.'"'>;

What I'd like to do for $quantity is something like this:

$quantity = $_POST['{$filename.$size}'];

Is it possible to use a variable with $_POST?

Upvotes: 0

Views: 229

Answers (2)

MattKnowles
MattKnowles

Reputation: 11

$_POST[$var1.$var2] worked. Nothing came up in my initial search of previous answers, although I see several applicable questions in the related questions on this page.

Upvotes: 0

mike.k
mike.k

Reputation: 3427

I think you're looking for this:

$quantity = htmlentities($_POST["$filename$size"]);

htmlentities() is necessary in case you have " or other junk in the input

Upvotes: 1

Related Questions