php $_GET 在提交表单后失去值(value),所以我无法使用它更新数据库表

标签 php html mysql forms get

这是我尝试更新数据库页面的页面

一切都是正确的,除了在最初提交表单后丢失 $_get 中的值但它丢失了的部分

$active_id=$_GET['client_id'];



 $query = "UPDATE clients SET name='$updatedName1',surname = '$updatedSurname', tel1='$updatedTel1', tel2='$updatedTel2', id_num='$updatedTel2', 
                                         address='$updatedAddress1' WHERE client_id = '$active_id' ";

这是我从中获取值的页面,

 if ( $name != ''){
                  echo "<tr>", "<td>", "<a  href=\"display_row.php?client_id=$id\">",$id_num, "   " ,$name ,"    ",$surname,"</a>","</td>","</tr>";

echo "<form method ='POST' name = 'update' action='display_row.php'>";
            echo "</br>";
            echo "</br>";
            echo  "<th style='color:green' >name</th><th style='color:green'>surname</th>"; 
            echo  "<tr >","<td>","<input type ='text'  name ='surname' value ='$Fname'>","<td>","<input type ='text' name ='name' value ='$Fsurname'>","</td>","</tr>";
            echo "</table>";
            echo  "</br>";
            echo  "</br>";
            echo "<table>";
            echo  "<th style='color:green' >Telephone1</th><th style='color:green'>Telephone2</th>"; 
            echo  "<tr >","<td>","<input type ='text'  name ='tel1' value ='$Ftel1'  >","<td>","<input type ='text' name ='tel2' value ='$Ftel2'>","</td>","</tr>";
            echo "<table>";
            echo "<tr>","<td>","<label style='color:green'>Id No: ","</td>","</tr>", "<tr>","<td>","<input type ='text' name ='id_num' value ='$Fid_num' >","</td>","</tr>","</br>","</br>";
            echo "<tr>","<td>","<label style='color:green'>Address: " ,"</td>","</tr>", "<tr>","<td>", "<input type ='text' name ='address' value ='$Faddress' >","</td>","</tr>","</br>","</br>";
            echo "</table>","</br>","</br>";
            echo "<input type ='submit'  style='color:green;width:120;height:60;border-radius: 25px;' name= 'go' value ='Update'>";
            echo "</br>";
            echo "</br>";
            echo "</br>";
           echo "</form>";

最佳答案

有两种可能的解决方案:

  1. 将您的 GET 值插入到 action

     <form action='<your_action>&client_id=<?=$_GET["client_id"]?>'>
    
  2. GET 值使用隐藏的 input,然后使用 $_POST 而不是 $_GET

     <input type='hidden' name='client_id' value='<?=$_GET["client_id"]?>'>
    

关于php $_GET 在提交表单后失去值(value),所以我无法使用它更新数据库表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31504543/

相关文章:

php - jQuery Ajax 表单仅发送几个复选框值中的最后一个

php - 在 Azure 上为 Laravel 应用程序设置存储磁盘时遇到问题

php - 在查询中连接多个 MySQL 表

javascript - 如何在点击时使用 jQuery 添加标题子菜单?

mysql - 使用 RAND 但遵循定义的结构进行查询

php - MySQL SELECT 查询获取记录如果 is_default = 1 否则 is_default = 0?

javascript - 菜单不是绝对 href 与位置 href 问题比较

javascript - 计算每个 div 的总高度

PHP system() 使用 MySQL 在许多数据库上运行查询

php - 单击 php 中的链接(来自数据库)后没有任何显示