-3

Possible Duplicate:
Inserting text from textarea into MySQL database without losing formatting

Can anybody tell me how to make the submit button submit the content of the textarea to a table? I know it is some very simple problem, but unfortunately i've been unable to find any solution for days.

This is the code:

  <div class="textareawrapper">
<textarea name="reddilemma" Class="redtext" rows="4" cols="30" onclick="this.value = firstToUpper(this.value)" value="$reddata"></textarea>
<textarea name="bluedilemma" Class="bluetext" rows="4" cols="30" onclick="this.value = firstToUpper(this.value)"></textarea>

      </div>
    <input type="submit" Class="submit" />

<?PHP

$user_name = "blabla";
$password = "blablabla";
$database = "blabla_database";
$server = "localhost";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
$reddata = $_post['reddilemma'];
$bluedata = $_post['bluedilemma'];

if ($db_found) {

$SQL = "INSERT INTO dilemma_id (reddilemma, bluedilemma) VALUES ('$reddata', '$bluedata')";
$result = mysql_query($SQL);

mysql_close($db_handle);

print "";
}
else {
print "Database NOT Found ";
mysql_close($db_handle);
}
Community
  • 1
  • 1
Jonas Pedersen
  • 911
  • 2
  • 10
  • 21
  • You could try this existing answer I found by Googling "php submit textarea to mysql": http://stackoverflow.com/questions/5863320/inserting-text-from-textarea-into-mysql-database-without-losing-formatting – Tom Black Oct 30 '12 at 19:03
  • [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained and the [deprecation process](http://j.mp/Rj2iVR) has begun on it. See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – tereško Oct 30 '12 at 19:07

2 Answers2

0

PHP variable names are case sensitive, you want to access $_POST not $_post, so try this:

$reddata = $_POST['reddilemma'];
$bluedata = $_POST['bluedilemma'];
Nelson
  • 49,283
  • 8
  • 68
  • 81
  • The thing is, that the button isn't even connected to the PHP code. I'm not aware of how to do that. – Jonas Pedersen Oct 30 '12 at 19:03
  • You need to enclose your ` – Nelson Oct 30 '12 at 19:06
0

You need to wrap your elements with <form> tag to submit data.

Skpd
  • 670
  • 3
  • 17