title: send data to MySQL with AJAX + jQuery + PHP
body: <p>I've been looking all day to find a way to insert some data into my database and then show the new data in the list of already existent data on my webpage.</p>
  
  <p>I know that some of the points I can't get done may be basics but I just started learning Javascript/ AJAX so I have a limited knowledge. </p>
  
  <p>I think that 70% of the job is done, I can display the data on my webpage using AJAX/jQuery/PHP but I can't figure how to send data from a "textarea" to my database using again AJAX/jQuery/PHP.</p>
  
  <p>So far this is what I've done :</p>
  
  <p>index.php<br>
  In this page, I figure that I need to put an onClick: function() on the button but I don't know where to put that function and what it should exactly do.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
      &lt;title&gt;TP2&lt;/title&gt;
      &lt;script src="jquery-1.10.2.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
   &lt;script src="javascript.js"&gt;&lt;/script&gt;
  
  
  
  
      Message: &lt;input type="text" id="message-content"&gt;
      &lt;input type="button" id="message-submit" value="Envoyer"&gt;
  
  
      &lt;div id="output" align="center"&gt;    
      &lt;/div&gt;    
  
  &lt;/body&gt;  
  &lt;/html&gt;
  </code></pre>
  
  <p>javascript.js<br>
  This page contain the AJAX code that display my data in the #output div.
  I just don't know what to put in "data: {}" so the content of my textarea is sent to my php file.</p>
  
  <pre><code>$.ajax({
      url: "messages.php",
      type: "POST",
      async: true, 
      data: { WHAT GOES HERE ? },
      dataType: "html",
  
      success: function(data) {
          $('#output').html(data);    
      },  
  });
  </code></pre>
  
  <p>messages.php<br>
  I know that the INSERT query will go here but I can't figure how to get the value from the POST of my textarea. </p>
  
  <pre><code>&lt;?php
  
  $host = "localhost";
  $user = "root";
  $pass = "root";
  $databaseName = "myDataBaseName";
  $tableName = "comments";  
  
  $con = mysql_connect($host,$user,$pass);
  $dbs = mysql_select_db($databaseName, $con);
  
  $result = mysql_query("SELECT * FROM $tableName ORDER BY date DESC LIMIT 0 , 10 ");            
  $data = array();
  
  while ($row = mysql_fetch_array($result)) 
  {
  echo $row['message']." - ".$row['date'];
  echo "&lt;br /&gt;";
  }
  
  ?&gt;
  </code></pre>