Take the 2-minute tour ×

how do i write textarea value from $repvalue value if the condition is true please help me.

    <form action="find4.php" method="post" name="finrep">
    <p>Find: <input type="text" name="fin">Replace: <input type="text" name="rep" >
    <textarea name="comments" cols="25" rows="5" value="<?php echo $repvalue; ?>"></textarea>
    <input type="submit" name="submit1" value="submit">
    if ($_POST['submit1'])
    $findval = $_POST['fin'];
    $textboval = $_POST['comments'];
    if($findval == $textboval){
    $repvalue = $_POST['rep'];
share|improve this question
what happens when u press submit? is there any errors? –  Swarne27 Jan 2 '13 at 6:30

2 Answers 2

up vote 7 down vote accepted

Close, but for a textarea you actually place the text between the tags, like this:

<textarea name="comments" cols="25" rows="5"><?php echo $repvalue; ?></textarea>

Also, you may want to clean the value of $repvalue with htmlenitites before outputting it, as any </textarea> tags in the variable will break your page.

And as per charlietfl's comment you need to make sure your definition of $repvalue needs to be before you try to output it (nice catch, didn't even look at that).

share|improve this answer
also need to define $repvalue; before try to echo it –  charlietfl Jan 2 '13 at 6:30

You must put the textarea value in between the tags

<textarea><?php echo $repvalue; ?></textarea>
share|improve this answer

Your Answer


