因此,我不得不非常自豪地说,我设法建立了一个文本框,用输入的内容更新数据库中的字段并显示此值。然而,每当我按下submit时,只有我在编辑之前的值存在,为了获得新的文本,我需要再次刷新。我不知道为什么,所以我想在这里问一下。
就像我说的,它确实会更新数据库中的表,只是不会立即显示新值。。。此外,当我从另一个页面点击页面时,文本字段不会自动加载文本并在字段中显示。。。我必须重新加载它。这是代码:
<?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());
$NOTE = mysql_query("SELECT note FROM notepad") or die(mysql_error());
$NOTE = mysql_fetch_object($NOTE);
mysql_query("UPDATE notepad SET note = '$_POST[note]' WHERE id = '1'") 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="note" id="note" style="width:380px;height:481px; padding:50px ;background:url('http://i686.photobucket.com/albums/vv221/LilyLoganBing/scrollnotes.png'); border:1px #000000">
<?php
echo "$NOTE->note";
?>
</textarea><br>
<input type="submit" value="Submit"></center>
<?php
incFooter();
?>
在更新"注释"行之前,您正在进行选择
每次运行脚本时,都会执行所有数据库查询。您需要一些控制逻辑来处理何时执行查询。
最简单的方法是添加一个隐藏的输入字段,其属性设置如下:
<input type="hidden" name="submitted" value="submitted" />
检查表格是否已提交:
if(isset($_POST['submitted'])) {
//do database updating here
}
PHP语言只在服务器机器上解析一次,而不是在用户机器上。如果您需要它来显示更新后的值,您还必须实现javascript。