我在HTML中有一个textarea,登录用户可以输入和保存注释。我使用下面的脚本从数据库单击保存按钮时,如何使用PHP将textarea中的文本保存到MySQL数据库中?
<?php
function notes() {
$password = "fake_password";
$connect = mysql_connect("localhost", "user", $password) or die("Couldn't connect to the database!");
mysql_select_db("db_name") or die("Couldn't find the database!");
$query = mysql_query("SELECT * FROM users WHERE notes!=''");
$numrows = mysql_num_rows($query);
if ($numrows != 0) {
while ($row = mysql_fetch_assoc($query)){
$notes = $row['notes'];
}
echo $notes;
}
}
?>
这工作都好得很,但检索保存的笔记现在 - 我怎么保存用户的笔记(文本域)单击保存按钮时所做的更改?
编辑:
这里是形式本身:
<div class="row-fluid">
<div class="span12">
<br />
<center><textarea class="input-xxlarge" rows="15"><?php include('includes/func.php'); notes(); ?></textarea>
<br />
<button class="btn btn-primary">Save Changes</button>
</center>
</div>
</div>
这非常广泛。开始阅读[关于'UPDATE'语句](http://dev.mysql.com/doc/refman/5.0/en/update.html),然后是[PHP中的$ _POST超全局](http:// php.net/manual/en/reserved.variables.post.php)我们没有足够的信息来给出任何特定的答案 - 你的表单发布到PHP,你逃避输入,并执行一个'UPDATE'语句(或'INSERT'用于新行。 –
textarea上没有'name ='属性,这意味着当提交表单时无法从'$ _POST'变量中获取它。跟踪用户ID? –