Page 1 of 1

TEXTAREA filled with variable

Posted: Fri Jun 18, 2010 4:18 am
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?

Re: TEXTAREA filled with variable

Posted: Fri Jun 18, 2010 4:41 am
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.

Re: TEXTAREA filled with variable

Posted: Fri Jun 18, 2010 4:59 am
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.

Re: TEXTAREA filled with variable

Posted: Fri Jun 18, 2010 7:32 am
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.

Re: TEXTAREA filled with variable

Posted: Fri Jun 18, 2010 8:06 am
by aravona
Don't you need a few semi colons in there?

Code: Select all

<?php echo $row['thearticle']; ?>
Maybe just be me nitpicking?

Re: TEXTAREA filled with variable

Posted: Fri Jun 18, 2010 8:13 am
by gazzieh
Ignore me. All working now. Not too sure what I have done to correct it but it now works. Wierd!

Re: TEXTAREA filled with variable

Posted: Thu Jun 24, 2010 1:12 am
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.