4

It is a very simple form as in the code below:

 <form method="POST" action="news.php?nid=2">
  <textarea id="txtcomment" style="width:100%; height: 70px;" maxlength="300"></textarea><br /><br />
  <input type="submit" class="button" style="float: right; cursor:pointer;" value="Comment">
 </form>

but in the news.php i cannot get the value of "txtcomment"

 echo $_POST['txtcomment'];

it returns nothing...

medo ampir
  • 1,850
  • 7
  • 33
  • 57

7 Answers7

15

It is because you need to name the textarea:

<textarea name="txtcomment"></textarea>

The id parameter does not have anything to do with how forms work (with the exception of labels, but that is not important here).

Sverri M. Olsen
  • 13,055
  • 3
  • 36
  • 52
4

Specify the name attribute of the textarea.

Richard
  • 455
  • 6
  • 15
4

Add name attribute in textarea

<textarea id="txtcomment" name="txtcomment" style="width:100%; height: 70px;" maxlength="300"></textarea>
Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70
4

you need to have an attribute name with txtcomment in it, you have an attribute 'id'

Hendrik
  • 1,355
  • 3
  • 11
  • 30
4

You have to define a name attribute (the id attribute is possible but not necessary).

<textarea name="txtcomment" ...>
bwoebi
  • 23,637
  • 5
  • 58
  • 79
4

textarea name must be txtcomment not id like

<form method="POST" action="news.php?nid=2">
<textarea id="txtcomment" name="txtcomment" style="width:100%; height: 70px;" maxlength="300"></textarea><br /><br />
<input type="submit" class="button" style="float: right; cursor:pointer;" value="Comment">
</form>
mohammad mohsenipur
  • 3,218
  • 2
  • 17
  • 22
3

It's not id="" that names the field in your array, it's name="".

<textarea name="txtcomment" id="txtcomment" style="width:100%; height: 70px;" maxlength="300"></textarea><br /><br />
JRL
  • 840
  • 6
  • 18