提交时保存和检索文本框中的值


Saving and Retrieving value from text box when submitted

我想创建一个文本框,它可以编辑并显示文本框中的文本(希望这有意义)。我已经设法得到了文本框,我有一个提交按钮和一切。然而,由于我仍在学习php和脚本,我不知道如何让这个字段显示所写的内容。目前,无论我键入什么并提交什么,在提交时都会消失(我知道为什么,只是不知道如何将输入的文本保存到数据库或其他文件中。)如果有任何帮助,我们将不胜感激。

这基本上就是我的整个脚本:

<?php
  session_start();
  include_once("include.inc.php");
  incHeader();

  // make sure staff only are here
  newbouncer(2);
   // include forum code
  include_once("forum-code.php");

mysql_query("UPDATE online SET location = 'My Preferences' WHERE userid = '" . $userID . "'") or die(mysql_error());

echo "</span></p> 

    </span>
<center><img src='"/layout/images/notepad.png'"></center><p>
      ";
?>
<center><form action="/notes.php" method="post">
<textarea name="comments" id="comments" style="width:380px;height:481px; padding:25px ;background:url('http://i686.photobucket.com/albums/vv221/LilyLoganBing/scrollnotes.png'); border:1px #000000">
To-Do's:

</textarea><br>
<input type="submit" value="Submit"></center>
<?php
  incFooter();
  ?>

提交表单时,文本区域内的文本存储在$_POST['comments']中。提交后,你可以做任何你喜欢的事。

示例如何将其存储在MYSQL数据库中。将这段代码放入表单处理脚本中,该脚本将在按下提交按钮后运行。

INSERT INTO comments VALUES('.$_POST['comments'].')

要将MYSQL数据库中的文本放回文本区域,请使用以下命令:

$sql = 'SELECT text FROM comments'
   $res = mysql_query($sql);
   $row = mysql_fetch_assoc($res);
   <teaxtarea name='comment'>$row['text']</textarea>

希望这将是你的答案

<?php
  session_start();
  include_once("include.inc.php");
  incHeader();

  // make sure staff only are here
  newbouncer(2);
   // include forum code
  include_once("forum-code.php");

$query = mysql_query("UPDATE online SET location = 'My Preferences' WHERE userid = '" . $userID . "'") or die(mysql_error());
$rs = mysql_fetch_array($query);
echo "</span></p> 

    </span>
<center><img src='"/layout/images/notepad.png'"></center><p>
      ";
?>
<center><form action="/notes.php" method="post">
<textarea name="comments" id="comments" style="width:380px;height:481px; padding:25px ;background:url('http://i686.photobucket.com/albums/vv221/LilyLoganBing/scrollnotes.png'); border:1px #000000">
<?php echo $rs['comment']; ?> // field name from database, i.e comment
</textarea><br>
<input type="submit" value="Submit"></center>
<?php
  incFooter();
  ?>