Friday, 27 September 2013

I have a blank page after submitting a php mysqli update form,

I have a blank page after submitting a php mysqli update form,

Hi I am trying to complete this update and It keeps sending me a blank
page with no errors and not submitting the info into the DataBase.
Everything works up to the point of the prepared statement as far as i can
tell, it draws the id and the other variables no problem from the database
and the previous search queries but wont let me go any further. Can anyone
see where I have gone wrong, I just cant see it???
<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");
}
}
}

No comments:

Post a Comment