TEXTAREA filled with variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

TEXTAREA filled with variable

Post by gazzieh »

I have a form with a textarea and I want to pre-populate it with relevant data.

I tried:

Code: Select all

<?php echo '<textarea name="thearticle" id="thearticle">'.$row['thearticle'];?>.'</textarea>'; ?>
Yet this does not work. If I simply echo the article piece (outside the textarea) then the article appears and if I remove the textarea from within the PHP and insert the word 'duckling' instead of the variable then that works, but I cannot seem to be able to pre-populate using the variable.

Where am I going wrong?
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: TEXTAREA filled with variable

Post by yacahuma »

There is no reason for you to put everything in php. Plus you have and additional ?> in your code

Do it like this. Your code will be easier to maintain.

Code: Select all

<textarea name="thearticle" id="thearticle"><?php echo $row['thearticle']?></textarea>
I prefer the short <?=$row['thearticle']?> But I am not sure is this is going to be depricated
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Re: TEXTAREA filled with variable

Post by gazzieh »

yacahuma wrote:There is no reason for you to put everything in php. Plus you have and additional ?> in your code

Do it like this. Your code will be easier to maintain.

Code: Select all

<textarea name="thearticle" id="thearticle"><?php echo $row['thearticle']?></textarea>
I prefer the short <?=$row['thearticle']?> But I am not sure is this is going to be depricated
Sorry about the additional ?>; wasn't in the code but only in my posting.

I did actually try your suggestion previously and got the same result; nothing.

Code: Select all

<textarea name="thearticle" id="thearticle">
<?php echo $row['thearticle']; ?>
</textarea>
As I say, the interesting thing is that if I post the line <?php echo $row['thearticle'] ?> anywhere outside the form then the contents appear; but not inside the textarea.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: TEXTAREA filled with variable

Post by yacahuma »

did you check the validity of your html?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: TEXTAREA filled with variable

Post by Benjamin »

:arrow: Duplicate = Locked
Locked