目前,我使用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 關注
- 128 瀏覽
添加回答
舉報
0/150
提交
取消