嗨,我正在尝试完成此更新,它一直向我发送一个没有错误的空白页面,并且没有将信息提交到数据库中。据我所知,一切都在准备好的语句中起作用,它从数据库和以前的搜索查询中提取 id 和其他变量没有问题,但不会让我走得更远。谁能看到我哪里出错了,我就是看不到???
<html>
<head>
<title>
<?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<h1><?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?></h1>
<?php if ($error != '') {
echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error
. "</div>";
} ?>
<form action="" method="post">
<div>
<?php if ($id != '') { ?>
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<p>ID: <?php echo $id; ?></p>
<?php } ?>
<br><strong>Item Type: * </strong><input name="item_type" value="<?php echo $item_type; ?>" type="text"><br>
<br><strong>Location: * </strong><input name="location" value="<?php echo $location; ?>" type="text"><br>
<br><strong>Date Last Test: * </strong><input name="date_last_test" value="<?php echo $date_last_test; ?>" type="date"><br>
<br><strong>Serial Number: *</strong><input name="serial_number" value="<?php echo $serial_number; ?>" type="text"><br>
<br><strong>Date Next Test: *</strong><input name="date_next_test" value="<?php echo $date_next_test; ?>" type="date"><br>
<br><strong>Comments: *</strong><input name="comments" value="<?php echo $comments; ?>" type="text"><br>
<p style="text-align: left;">* required</p>
<input name="submit" value="Submit" type="submit"><div style="text-align: left;">
</div></div><div style="text-align: left;">
</body>
</html>
/*
EDIT RECORD
*/
// if the 'id' variable is set in the URL, we know that we need to edit a record
if (isset($_GET['id']))
{
// if the form's submit button is clicked, we need to process the form
if (isset($_POST['submit']))
{
// make sure the 'id' in the URL is valid
if (is_numeric($_POST['id']))
{
// get variables from the URL/form
$id = $_POST['id'];
$item_type = htmlentities($_POST['item_type'], ENT_QUOTES);
$location = htmlentities($_POST['location'], ENT_QUOTES);
$date_last_test = htmlentities($_POST['date_last_test'], ENT_QUOTES);
$serial_number = htmlentities($_POST['serial_number'], ENT_QUOTES);
$date_next_test = htmlentities($_POST['date_next_test'], ENT_QUOTES);
$comments = htmlentities($_POST['comments'], ENT_QUOTES);
// check that firstname and lastname are both not empty
if ($item_type == '' || $location == ''|| $date_last_test == ''|| $serial_number == ''|| $date_next_test == ''|| $comments == '' )
{
// if they are empty, show an error message and display the form
$error = 'ERROR: Please fill in all required fields!';
renderForm($item_type, $location, $date_last_test, $serial_number, $date_next_test, $comments, $error, $id);
}
else
{
// if everything is fine, update the record in the database
if ($stmt = $mysqli->prepare("UPDATE `Calibration_and_Inspection_Register` SET `item_type` = ?, `location` = ?, `date_last_test` = ?, `serial_number` = ?, `date_next_test` = ?, `comments` = ?
WHERE `id`=?"))
{
$stmt->bind_param("issdsds",`$id`, `$item_type`, `$location`, `$date_last_test`, `$serial_number`, `$date_next_test`, `$comments`);
$stmt->execute();
$stmt->close();
}
// show an error message if the query has an error
else
{
echo "ERROR: could not prepare SQL statement.";
}
// redirect the user once the form is updated
//header("Location: View Calibration and Inspection records.php");
}
}
// if the 'id' variable is not valid, show an error message
else
{
echo "Error with ID !";
}
}
// if the form hasn't been submitted yet, get the info from the database and show the form
else
{
// make sure the 'id' value is valid
if (is_numeric($_GET['id']) && $_GET['id'] > 0)
{
// get 'id' from URL
$id = $_GET['id'];
// get the recod from the database
if($stmt = $mysqli->prepare("SELECT `item_type`,`location`,`date_last_test`,`serial_number`,`date_next_test`,`comments`,`id` FROM `Calibration_and_Inspection_Register` WHERE id=?"))
{
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->bind_result($item_type, $location, $date_last_test, $serial_number, $date_next_test, $comments, $id);
$stmt->fetch();
// show the form
renderForm($item_type, $location, $date_last_test, $serial_number, $date_next_test, $comments, $id);
$stmt->close();
}
// show an error if the query has an error
else
{
echo "Error: could not prepare SQL statement";
}
}
// if the 'id' value is not valid, redirect the user back to the view.php page
else
{
header("Location: View All Calibration and Inspection Records.php");
}
}
}