user975582
user975582

Reputation: 205

How can i set the value of a text area with php?

I have two issues:-
1. I need to be able to set the value of a textarea
2. I need to then get the value of the text area again for updating. I see that text area does not have a 'value' tag or something.. so I am not sure how to do this via PHP. I tried something like

print("<textarea cols='15' rows='2' name='textdesc'>$info_desc</textarea>");

to set it. But no luck and then i will have the same problem when retrieving.

Upvotes: 1

Views: 17602

Answers (4)

abstracto
abstracto

Reputation: 1

$info_desc is actually value of your textarea. If you submit it, you will get the same value for $_REQUEST['textdesc'].

Upvotes: 0

melbOro
melbOro

Reputation: 17

Mayby your variable are undefind?

I try this code and it works correct.

$info_desc = "12345";
print("<textarea cols='15' rows='2' name='textdesc'>$info_desc</textarea>");

Upvotes: 2

Phil
Phil

Reputation: 164742

To set the value in HTML...

<textarea cols="15" rows="2" name="textdesc"><?php echo htmlspecialchars(
    $info_desc, ENT_QUOTES, 'UTF-8') ?></textarea>

To retrieve it (assuming your form issues a POST request)...

if (isset($_POST['textdesc'])) {
    $textdesc = $_POST['textdesc'];
}

Upvotes: 4

Itai Sagi
Itai Sagi

Reputation: 5615

the value of the textarea is within <textarea>VALUE</textarea>.

Upvotes: 3

Related Questions