간략하게 말하면 PDO 삽입 성공 후 리디렉션을 수행 할 방법을 찾고 있습니다. 여기까지 내가 지금까지 가지고있는 것이있다.PDO 삽입 성공 후 리디렉션 기능
<?php
function redirect_to($new_location) {
header("Location: " . $new_location);
exit;
}
?>
PDO INSERT가
있습니다 리디렉션에 대한
기능, 나는 쉽게 읽을 수 있도록 아래에있는 내 예제에서 몇 가지 코드를 손질했습니다.
try {
$sql = "INSERT INTO location_info (`department`, `participant`, `activity`, `location`, `rec_injuries`, `rec_injuries_timeframe`, `non_rec_injuries`)
VALUES (:department, :participant, :activity, :location, :rec_injuries, :rec_injuries_timeframe, :non_rec_injuries, :non_rec_injuries_timeframe, '{$id}')";
$stmt = $db->prepare($sql);
for($i = 0, $l = count($_POST["department_name"]); $i < $l; $i++) {
$loc_info = array(':department' => $_POST["department_name"][$i],
':rec_injuries_timeframe' => $_POST["injury_time_frame"][$i],
':non_rec_injuries' => $_POST["non_rec_injuries"][$i],
':non_rec_injuries_timeframe' => $_POST["non_rec_injury_timeframe"][$i],
':competitor' => $_POST["competitor"][$i],
':cost_per_pair' => $_POST["cost_per_pair"][$i],
':usage_rate' => $_POST["usage_rate"][$i],
':leakage' => $_POST["leakage"][$i],
':cost_of_productivity' => $_POST["cost_of_productivity"][$i],
':non_rec_impact' => $_POST["non_rec_impact"][$i],
':non_rec_sprain' => $_POST["non_rec_sprain"][$i],
':non_rec_puncture' => $_POST["non_rec_puncture"][$i],
':non_rec_dermatitis' => $_POST["non_rec_dermatitis"][$i],
':non_rec_infection' => $_POST["non_rec_infection"][$i],
':non_rec_burns' => $_POST["non_rec_burns"][$i],
':non_rec_cuts' => $_POST["non_rec_cuts"][$i],
':rec_impact' => $_POST["impact"][$i],
':rec_sprain' => $_POST["sprain"][$i],
':rec_puncture' => $_POST["puncture"][$i],
':rec_dermatitis' => $_POST["dermatitis"][$i],
':rec_infection' => $_POST["infection"][$i],
':rec_burns' => $_POST["burns"][$i],
':rec_cuts' => $_POST["cuts"][$i],
':condition' => $_POST["condition"][$i]);
$stmt->execute($loc_info);
}
if ($stmt->execute()) {
redirect_to($_SERVER["DOCUMENT_ROOT"]."/testing/tim/results.php");
}
}
catch (Exception $e) {
$error = $e->getMessage();
print "<b>error:</b> " . $error;
}
내가 어디 잘못 가고 if ($stmt->execute()) { redirect_to($_SERVER["DOCUMENT_ROOT"]."/testing/tim/results.php");
로 리디렉션에 대한 if 문을 가지고 당신이 볼 수?
하지 마십시오 'redirect_to'는 PHP에서의 일이라고 생각합니다. 'header ('Location : '.'new/path/file.php ');' – nerdlyist
질문을 좀 더 명확하게하고 싶을 수도 있습니다 .... AFTER all 진술이 실행 되었습니까? 모든 명령문을 작성한 다음 대량으로 실행하고 모두 성공한 후에 리디렉션하려고합니까? – Zach
은'$ stmt-> execute()'가 두 번 호출 되는가? 아마도 두 번째로 기대했던 것과 같은 쿼리를 실행하지 않을 것입니다. 그리고'$ loc_info'의 값 할당 위의 블록에 무엇이 있습니까? if 문 위에 닫는 중괄호가 있습니다. 그래서 위에 무엇이 있는지 모른다면 우리가 알기가 어렵습니다. –