更新数据库并更新where变量



我有一个关于GET函数的问题。我目前有一个表单与get动作。我访问该数据在另一个页面与get函数。不幸的是,我得到了一个"错误:未定义的索引"对我的每一个值。在阅读了类似的问题之后,我尝试使用isset(如下所示),它消除了错误,但我不确定我的数据是否存储在变量中,因为如果我回显4个变量,什么也没有显示。有人能给我指个路吗?

数据来自表格:

while($row = mysql_fetch_array($result)) {
echo "<div class="addform"><form method='GET' action="update.php">n";
echo "  <input type="text" value="".$row['tfid']."" name="tfid">n";
echo "  <input type="text" name="fname"      value="".$row['fname'].""/>n";
echo "  <input type="text" name="lname" value="".$row['lname'].""/>n";
echo "  <input type="text" name="hca" value="".$row['hca'].""/>n";
echo "  <input type="text" name="file" value="".$row['file'].""/>n";
echo "  <input type="image" src="images/update.png" alt="Update Row" class="update" title="Update Row">n";
echo "<a href="delete.php?tfid=".$row['tfid'].""><img title='Delete Row' alt="Delete" class='del' src='images/delete.png'/></a></form></div>n";
}
echo "</table><br />n";

和检索代码:

$tfid= isset($_GET["tfid"]) ? $_GET["tfid"] : NULL;
$fname = isset($_GET["fname"]) ? $_GET["fname"] : NULL;
$lname = isset($_GET["lname"]) ? $_GET["lname"] : NULL;
$hca = isset($_GET["hca"]) ? $_GET["hca"] : NULL;
echo $tfid;
echo $fname;
echo $lname;
echo $hca;

编辑后:

在您发布表单代码后,我注意到问题可能是输入的值可能是空的,因为语法看起来或多或少是正确的。通过view-source仔细检查值以确保其有效性。


编辑前:

出现错误是因为变量实际上是而不是设置。确保你的表单看起来像这样:

<form action="yourpage.php">
<input name="fname" type="text" />
<input name="lname" type="text" />
<input name="hca" type="text" />
<input name="tfid" type="text" />
</form>
如上面所示,_GET变量正在查找name属性。初学者常犯的一个错误(每个人都曾犯过这样的错误)是用id代替nameid用于选择器,而name通常用于在服务器端检索值。

注意事项....

正如@George Cummins所提到的,您还应该意识到$_GET参数是这样通过URL传递的:

http://yoururl.com?var1=data1&var2=data2

在某些情况下,您可能不希望用户看到通过表单发送的所有数据,因此在这种情况下,您可能希望使用$_POST,这实际上是表单数据的隐藏传递。实际上,这些数据并不是真正隐藏的,但它肯定比$_GET的使用更隐藏。

最新更新