php - 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>
解决方案
在edit-field.php 中,通过URL 传递的参数变量是$_GET 而不是$GET。
将该文件的开头更改为:
if(isset($_GET["field_id"])) {
$field_id = $_GET["field_id"];
}
推荐阅读
- angular - 如果不存在,则替换 ngModel 的值
- php - 如何从头到尾注释掉整个php代码?
- google-analytics - 标记管理器和 Pardot 表单
- r - 使用 prop.table 时维护字符列
- javascript - 如何获取在 JavaScript 中使用脚本标记动态加载的 JavaScript 模块的引用?
- java - 无法将字符串转换为双向链表节点
- c# - 如何使用 Windows 运行时使用 C# 实现 C++ API?
- python - 单行if else return语句的Python不同输出
- html - CSS/HTML 按钮动画不正确
- jenkins - 如何根据执行结果在 Jenkins Pipeline 中设置当前构建结果?