1

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

1
  • Your description is cryptic to me. More code would be a help. The line you posted $convert_post_to_variable = "$_POST[art_" . $b . "]"; creates a string variable with the contents "$_POST..." - that is probably not what you want (remove the outside quotes. Commented Jan 25, 2014 at 23:46

2 Answers 2

1

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];
Sign up to request clarification or add additional context in comments.

Comments

0

Use the following code:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.