user3103188
user3103188

Reputation: 49

PHP: Convert $_POST into variable?

I'm building a form that's in a loop, so that the user can choose how many rows they want to put into the database. And all my input-names have this value art_$i where $i is the number of the rows, that my loop generates.

When the form-button is pressed, I then try to pull out the value of each $_POST['art_X'] by creating a second loop that repeats itself the same amount of times as my $i loop that is naming by inputs as art_1, art_2, art_3 etc. This second loop I call $b, here's how I try to solve the problem.. It just isn't working at all!

$convert_post_to_variable = "$_POST[art_" . $b . "]";

Any suggestions on how I could solve this problem, would be MUCH APPRECIATED! :-D

Upvotes: 1

Views: 240

Answers (2)

darthmaim
darthmaim

Reputation: 5148

Use the following code:

$convert_post_to_variable = $_POST[ 'art_' . $b ];

Upvotes: 0

Brad
Brad

Reputation: 163272

Don't use quotes around variable names. It makes a mess of things, and then you would have to use curly brackets... just don't do it. You can use an arbitrary string key on an associative array like this:

$convert_post_to_variable = $_POST['art_' . $b];

Upvotes: 1

Related Questions