1

I'm trying to display a $_POST that has a variable within.

Here's my PHP code:

<?php if ($options) { ?>
<?php foreach ($options as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<textarea name="<?php echo $option['name']; ?>" rows="1" cols="20" class=""><?php echo '$_POST['.$option['name'].']' ?></textarea>
<?php } ?>
<?php } ?>
<?php } ?>

So far I'm able to display the $option['name'] variable.So, for <?php echo '$_POST['.$option['name'].']' ?>, I get $_POST[size] for exemple in the textarea.

Any idea how to work this out?

4 Answers 4

1

Variables inside single quotes are not parsed due to variable interpolation.

What you can do is:

Replace

<?php echo '$_POST['.$option['name'].']' ?>

By

<?php echo $_POST[$option['name']]; ?>
Sign up to request clarification or add additional context in comments.

Comments

1

I found error between textarea

change this line

<?php echo '$_POST['.$option['name'].']' ?>

to this

<?php echo $_POST[$option['name']] ?>

Comments

1

Use this line

 <?php echo $_POST[$option['name']] ?>

Comments

0

Try this:

<?php
if($options) {
    foreach($options as $option) {
        if($option['type'] == 'select')
            echo '<textarea name="', $option['name'], '" rows="1" cols="20">', $_POST[$option['name']], '</textarea>', "\n";
    }
}

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.