-5

I have a form with three fields two are of input type="text" and one is text area. I am not able to store the data of text area in database. HELP

<table>
  <form name="email" method="post">
    <tr>
      <td width="90">
        Email Id : <input name="Receiver1" type="text" size="70"/><br>
        Subject :<input name="Sub" type="text" size="70" /><br>

          <textarea cols="80" rows="30" >
          </textarea>

       Content:<input type="submit" name="Send" value="Send" />

  </form>
<?php
 require('connection.php');
 if(isset($_POST['Send']))
 {
   $Reciever = $_POST['Receiver1'];
   $Subject = $_POST['Sub'];
   $text = mysql_real_escape_string($_POST['textarea']);
   mysql_query("INSERT INTO EmailData VALUES ('$Reciever','$Subject', '$text')");
}
nbanic
  • 1,270
  • 1
  • 8
  • 11
  • What error do you get? (Not that you're actually checking). FYI, you are wide open to [SQL injections](http://stackoverflow.com/q/60174). – John Conde May 07 '14 at 19:33
  • 1
    Your textarea isn't named. Bingo. Can I have my cookie now? – Funk Forty Niner May 07 '14 at 19:34
  • **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin May 07 '14 at 19:34
  • Give your text area a name and look for it in $_POST, just like any other form variable. –  May 07 '14 at 19:35
  • Please [learn to love labels](http://www.456bereastreet.com/archive/200711/use_the_label_element_to_make_your_html_forms_accessible/) – Quentin May 07 '14 at 19:36
  • Next time, add error reporting to the top of your file(s) `error_reporting(E_ALL); ini_set('display_errors', 1);` and save us all the typing trouble. – Funk Forty Niner May 07 '14 at 19:37
  • the error is Undefined index: textarea – user3613632 May 07 '14 at 19:40
  • ^--« There you go, see? It works! ;-) Invaluable tool isn't it? So do ` – Funk Forty Niner May 07 '14 at 19:43

4 Answers4

1

You have to give a textarea a name attribute for it to be a successful form control.

You are not allowed a form around a table row element. Some browsers will move the form outside the table and leave the form controls behind. Use a validator.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
1

You need to name the textarea:

<textarea cols="80" rows="30" name="textarea">
</textarea>
fnightangel
  • 416
  • 3
  • 10
1

name your textarea :)

<textarea name="textarea_name" cols="80" rows="30" >
          </textarea>

  </form>
<?php
 require('connection.php');
 if(isset($_POST['Send']))
 {
   $Reciever = $_POST['Receiver1'];
   $Subject = $_POST['Sub'];

   $text = mysql_real_escape_string($_POST['textarea_name']);
   mysql_query("INSERT INTO EmailData VALUES ('$Reciever','$Subject', '$text')");
}
M.chaudhry
  • 651
  • 1
  • 6
  • 13
0

You have to name your <textarea> just like you name your <input>s:

<textarea cols="80" rows="30" name="sometext">
</textarea>

You can then refer to it as $_POST['sometext'].

That being said, please read up on SQL injection and how to program against it.

Community
  • 1
  • 1
Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195