首页 > 解决方案 > Data not transferred between 2 forms using php-echo

问题描述

I am working on making update functionality in an html form. I am sending data from one form to other through echo to be updated. But I am not able to populate other from catching the data send from 1st form.

The field id text box is blank.

Here is my code:

Sent key from from 1:

  <tr>
    <td style='width:150px;border:1px solid grey;'><?= $row['field_id'] ?></td>
    <td style='width:150px;border:1px solid grey;'><?= $row['description'] ?></td>
    <td style='width:150px;border:1px solid grey;'><?= $row['corner_points'] ?></td>
    <td style='width:150px;border:1px solid grey;'><?= $row['notes'] ?></td>
    <td style='width:150px;border:1px solid grey;'><a target="_blank" href="Edit/edit-field.php?field_id=<?php echo $row['field_id'];?>">Edit</a></td>
  </tr>

to receive data edit-field.php:

<?php

    if(isset($GET["field_id"]))    
      {
       $field_id = $GET["field_id"]; 
      }

     try {
            $stmt = $conn->prepare("SELECT field_id, description, corner_points, notes FROM fields where field_id = $field_id");
            $stmt->execute();

            $stmt->setFetchMode(PDO::FETCH_ASSOC);
            $result = $stmt->fetchAll();
        }

        catch(PDOException $e) {
        echo "Error: " . $e->getMessage();
        }
        ?>

   <form action="" method="post" class="needs-validation" novalidate enctype="multipart/form-data"> 
    <h6> Field </h6>
  <div class="form-row">
    <div class="col-md-4 mb-3">
      <label for="validationCustom01">Field ID</label>
      <input type="number" class="form-control" name="field_id" id="field_id" value="<?php echo $result["field_id"];?>">
      </div>
   </div>

  <button class="btn btn-primary btn-sm" name="submit1" type="submit">Update Records</button>
</form>

标签: phphtmlformspdo

解决方案


在edit-field.php 中,通过URL 传递的参数变量是$_GET 而不是$GET。

将该文件的开头更改为:

if(isset($_GET["field_id"])) {
   $field_id = $_GET["field_id"]; 
}

推荐阅读