データベースに投稿された後は、ユーザーを新しいページにリダイレクトし、直前に挿入したレコードのlast_idの結果を表示するポストPHPページがあります。投稿後にリダイレクトされない
データの投稿は正常に確認できますが、リダイレクトは機能していません。ちょうどそこに座って、とても悲しいようです。それは一度働いたが、今私はそれが再び働くように見えることができない。
問題のあるフラグメントである:
if ($conn->query($sql) === TRUE) {
$last_id = $conn->insert_id;
echo ' <head> <meta http-equiv="refresh" content="1;url=http://vmcnucmed.cvm.umn.edu/patientinjection/view_inj_info.php?id=' . $last_id;'"></head>
Patient Added Successfully. <br /><br />Database ID: ' . $last_id;'<br>';
}
その全体がスクリプトは次のとおりです。
<title>Post Patient Injection Information</title>
<?php
$erors = array(); // set an empty array that will contains the errors
// Check for form submission
if (isset($_POST['patientID']) && isset($_POST['lastname']) && isset($_POST['patientname'])&& isset($_POST['dose'])) {
// remove tags and whitespace from the beginning and end of form data
$_POST = array_map("strip_tags", $_POST);
$_POST = array_map("trim", $_POST);
// chech if all form fields are filled in correctly
// (minimum number of characters in "patientID")
if (strlen($_POST['patientID'])<3) $erors[] = 'Patient ID must contain at least 3 characters.';
// if no errors ($error array empty)
if(count($erors)<1) {
// connect to the "tests" database
$conn = new mysqli('somehost', 'someuser', 'somepassword', 'somedatabase');
// check connection
if (mysqli_connect_errno()) {
exit('Connect failed: '. mysqli_connect_error());
}
// store the values in an Array, escaping special characters for use in the SQL statement
$adds['pkgnumberID'] = $conn->real_escape_string($_POST['pkgnumberID']); // package number ID
$adds['rxnumber'] = $conn->real_escape_string($_POST['rxnumber']); // patient prescription number
$adds['patientID'] = $conn->real_escape_string($_POST['patientID']); // Patient ID/MRN number
$adds['lastname'] = $conn->real_escape_string($_POST['lastname']); // patient last name
$adds['patientname'] = $conn->real_escape_string($_POST['patientname']); // patient name
$adds['isotope'] = $conn->real_escape_string($_POST['isotope']); // isotope injected
$adds['radiopharmaceutical'] = $conn->real_escape_string($_POST['radiopharmaceutical']); // radiopharmaceutical injected
$adds['dose'] = $conn->real_escape_string($_POST['dose']); // dose injected
$adds['datetimestated'] = $conn->real_escape_string($_POST['datetimestated']); // date/time stated activity
$adds['datetimeadmin'] = $conn->real_escape_string($_POST['datetimeadmin']); // date/time administered
$adds['adminby'] = $conn->real_escape_string($_POST['adminby']); // administered by
// sql query for INSERT INTO tbl_patientdoseinformation
$sql = "INSERT INTO `tbl_patientdoseinformation` (`pkgnumberID`,`rxnumber`,`patientID`,`lastname`,`patientname`,`isotope`,`radiopharmaceutical`,`dose`,`datetimestated`,`datetimeadmin`,`adminby`)
VALUES ('". $adds['pkgnumberID']. "','". $adds['rxnumber']. "','". $adds['patientID']. "','". strtoupper($adds['lastname']). "','". strtoupper($adds['patientname']). "','". $adds['isotope']. "','". $adds['radiopharmaceutical']. "','". $adds['dose']. "','". $adds['datetimestated']. "','". $adds['datetimeadmin']. "','". $adds['adminby']. "')";
// Performs the $sql query on the server to insert the values
if ($conn->query($sql) === TRUE) {
$last_id = $conn->insert_id;
echo ' <head> <meta http-equiv="refresh" content="1;url=http://vmcnucmed.cvm.umn.edu/patientinjection/view_inj_info.php?id=' . $last_id;'"></head>
Patient Added Successfully. <br /><br />Database ID: ' . $last_id;'<br>';
}
else {
echo 'Error: '. $conn->error;
}
$conn->close();
}
else {
// else, if errors, it adds them in string format and print it
echo implode('<br />', $erors);
}
}
else {
echo 'No data from form';
}
?>
はい、これは完全に機能しました。どうもありがとうございました! –