gpt4 book ai didi

php - 更新数据库并更新变量

转载 作者:太空宇宙 更新时间:2023-11-03 12:29:25 24 4
gpt4 key购买 nike

我有一个关于 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 更隐藏。

关于php - 更新数据库并更新变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16149827/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com