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

Post Reply
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
hypedupdawg
Forum Commoner
Posts: 74
Joined: Sat Apr 10, 2010 5:21 am

Re: TEXTAREA filled with variable

Post by hypedupdawg »

You need to set the variable as the value of the text area like so:

Code: Select all

<?php echo '<textarea name="thearticle" id="thearticle" value="' . $row['thearticle'] . '></textarea>'; ?>
You also put in a second set of "?>" marks before - not quite sure why.

Anyway, this should work for you.
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Re: TEXTAREA filled with variable

Post by gazzieh »

hypedupdawg wrote:You need to set the variable as the value of the text area like so:

Code: Select all

<?php echo '<textarea name="thearticle" id="thearticle" value="' . $row['thearticle'] . '></textarea>'; ?>
You also put in a second set of "?>" marks before - not quite sure why.

Anyway, this should work for you.
Nah, VALUE works for inputs but not textarea. With TEXTAREA you need to put the text between the opening and closing statements but this is not working for the variable.

Yeah, my additional ?> was because I constructed my posted code from two lines since I was playing with the original and did not wish to revert back simply to paste the code. Sorry for that.
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Re: TEXTAREA filled with variable

Post by gazzieh »

I accidently duplicated this topic so sorry. :o(

Anyhow, the code I am having an issue with is below:

Code: Select all

<?php echo $row['thearticle'] ?>
<form name="form1" method="post" action="newArticle.php">
<p>&nbsp;Title:
<?php echo '<input name="title" type="text" id="title" value="'.$row['title'].'">'; ?>
</p>
</p>
<textarea name="thearticle" id="thearticle">
<?php echo $row['thearticle'] ?>
</textarea>
</p>
<p align="center">
<input type="submit" name="Submit" value="Submit">
</p>
</form>
The first line proves that thearticle does contain data. The textarea is where the issue lies.
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: TEXTAREA filled with variable

Post by aravona »

Don't you need a few semi colons in there?

Code: Select all

<?php echo $row['thearticle']; ?>
Maybe just be me nitpicking?
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Re: TEXTAREA filled with variable

Post by gazzieh »

Ignore me. All working now. Not too sure what I have done to correct it but it now works. Wierd!
arjel06
Forum Newbie
Posts: 1
Joined: Wed Jun 23, 2010 8:58 pm

Re: TEXTAREA filled with variable

Post by arjel06 »

I suggest, it's better if you will add color codes in your code. And try to add some semicolons there if it will work. Please inform us for the new result. We will see what can we do more about it.
Post Reply