可能重复:
Inserting text from textarea into MySQL database without losing formatting
有人能告诉我如何让提交按钮将textarea的内容提交到表格中吗?我知道这是一个非常简单的问题,但不幸的是我几天都找不到任何解决方案。
这是代码:
<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);
}
答案 0 :(得分:0)
PHP变量名称为case sensitive,您要访问$_POST
而非$_post
,请尝试以下操作:
$reddata = $_POST['reddilemma'];
$bluedata = $_POST['bluedilemma'];
答案 1 :(得分:0)
您需要使用<form>
标记包装元素以提交数据。