目前,我使用CRUD功能创建一个系统。我的更新功能有一些问题。问题是,它会在view_task.php显示错误,例如:1) 未定义的索引: report_id 在第 7 行 2) 未定义的变量: task_name 在第 50 行问题是,当我检查数据库时,数据已更新。以下是我当前的代码:仪表板.php echo "<form method = 'post' action = 'view_task/view_task.php'>"; echo "<input type = 'hidden' name = 'report_id' value = '".$report_id."'>"; echo "<button type = 'submit' class='btn-primary'>View</button>"; echo "</form>";view_task.php<?php require_once "../../../../config/configPDO.php"; require_once "../../../../config/check.php"; $report_id = $_POST['report_id']; //line 7 $sql = "SELECT * FROM ot_report LEFT JOIN ot_users ON ot_report.badgeid = ot_users.badgeid LEFT JOIN ot_team ON ot_team.team_id = ot_users.team_id WHERE report_id = :report_id"; $query = $conn->prepare($sql); $query->execute(array(':report_id' => $report_id)); while($row = $query->fetch(PDO::FETCH_ASSOC)){ $report_id = $row["report_id"]; $task_name = $row["task_name"]; }?><form action="update_task_name.php" method="POST"> <td><b>Task Name</b></td> <td colspan = '2'><input type="text" class="form-control" name="task_name" value="<?php echo $task_name; ?>"/></td> //line 50 <input type="hidden" name="report_id" value="<?php echo $report_id ?>"> <td><input type="submit" class="btn btn-primary btn-block" value = "Save" onclick="confirm('Are you sure?')"></td></form>update_task_name.php<?php require_once '../../../../config/configPDO.php'; $update = "UPDATE ot_report SET task_name = :task_name WHERE report_id = :report_id"; $stmt = $conn->prepare($update); $stmt->bindParam(':task_name', $_POST['task_name']); $stmt->bindParam(':report_id', $_POST['report_id']); $stmt->execute(); class Result {} $response = new Result(); $response->result = 'OK'; $response->message = 'Update successful'; header("Location: view_task.php");?>任何人都可以帮我解决这个问题吗?谢谢
1 回答
素胚勾勒不出你
TA贡献1827条经验 获得超9个赞
在view_task.php页面中,数据更新后未定义 $ _POST ['report_id'] 部分,因为在update_task_name.php,您使用的重定向标头(“位置:view_task.php”),该标头将成为 GET 方法
尝试更新
update_task_name.php
header ("Location: view_task.php?report_id=". $ _ POST ['report_id'])
view_task.php //第 7 行
if (isset ($_POST['report_id'])) {
$report_id = $_POST['report_id'];
} else if (isset ($_GET['report_id'])) {
$report_id = $_GET['report_id'];
} else {
die ("ID NOT DEFINED");
}
- 1 回答
- 0 关注
- 169 浏览
添加回答
举报
0/150
提交
取消
