【发布时间】:2012-10-30 00:09:03
【问题描述】:
我有一个 HTML 文本区域,登录用户可以在其中输入和保存注释。我使用以下脚本从数据库中检索保存的笔记
<?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;
}
}
?>
这一切都很好,但现在 - 当点击“保存”按钮时,如何保存用户对注释 (textarea) 所做的更改?
编辑:
这是表单本身:
<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>
【问题讨论】:
-
这个范围很广。开始阅读about
UPDATEstatements,然后是$_POSTsuperglobal in PHP 我们没有足够的信息来给出任何具体的答案——您的表单发布到 PHP,您转义输入,然后执行UPDATE语句(或 @ 987654328@ 用于新行。 -
您在 textarea 上没有
name=属性,这意味着在提交表单时无法从$_POST变量中获取它。另外,您如何/在哪里跟踪用户 ID?