biscuitboy
Technical User
Hi,
Im currently working on a residential database and working on the 'delete resident' page. Everything works and the correct reisdent gets deleted as wanted. The problem I have is that when the page loads up all of the "else" statements such as "you have forgot to enter your surname" appears when it shouldnt.
Can anyone help?
Regards
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Residents Database Admin User</title>
</head>
<body
style="background-image: url(file:///var/<img style="width: 121px; height: 153px;" alt=""
src="file:///var/ style="width: 357px; height: 99px;" alt=""
src="file:///var/ style="width: 299px; height: 99px;" alt=""
src="file:///var/<div style="text-align: center;"><img
style="width: 463px; height: 14px;" alt=""
src="file:///var/ <br>
<div style="text-align: left;">
<font size="+1"><span
style="text-decoration: underline; font-weight: bold; font-style: italic;">Search<br>
<br>
</span></font>
<table style="text-align: left; width: 50%;" border="1" cellspacing="2"
cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top;"><a href="buildingname.php"><img
style="width: 118px; height: 25px;" alt=""
src="file:///var/ <td style="vertical-align: top;"><a href="flatnumber.php"><img
style="width: 118px; height: 25px;" alt=""
src="file:///var/ <td style="vertical-align: top;"><a href="surname.php"><img
style="width: 118px; height: 25px;" alt=""
src="file:///var/ <td style="vertical-align: top;"><a href="viewresidents.php"><img
style="border: 0px solid ; width: 118px; height: 25px;" alt=""
src="file:///var/ </tr>
</tbody>
</table>
<div style="text-align: right;"><br>
</div>
<table
style="width: 28%; text-align: left; margin-right: auto; margin-left: 120px;"
border="1" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top; text-align: center;"><a
href="register.php"><img style="width: 118px; height: 25px;"
alt="" src="file:///var/ <td style="vertical-align: top; text-align: center;"><a
href="delete.php"><img style="width: 118px; height: 25px;"
alt="" src="file:///var/ </tr>
</tbody>
</table><br>
</div>
</div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>Enter your information in the form below:</legend>
<p><b>Last Name:</b> <input type="text" name="surname" size="30" maxlength="30"
value="<?php if (isset($_POST['surname'])) echo $_POST['surname']; ?>" /></p>
<p><b>First Name:</b> <input type="text" name="first_name" size="15" maxlength="15"
value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
<p><b>Flat No:</b> <input type="text" name="flat_no" size="15" maxlength="15"
value="<?php if (isset($_POST['flat_no'])) echo $_POST['flat_no']; ?>" /></p>
<p><b>Building Name:</b> <input type="text" name="building_name" size="15" maxlength="15"
value="<?php if (isset($_POST['building_name'])) echo $_POST['building_name']; ?>" /></p>
<div align="centre"><input type="submit" name"submit" value="Delete Record"></div>
</form><!-- end of form -->
<?php # Scrtipt 6.6 - register.php
$page_title = 'Add New Entry';
$message = NULL; // create an empty new variable.
//check for a surname
if (empty($_GET['surname'])) {
$ln = FALSE;
$message .= '<p>You forgot to enter your surname!</p>';
} else {
$ln = $_GET['surname'];
}
//check for a first name
if (empty($_POST['first_name'])) {
$fn = FALSE;
$message .= '<p>You forgot to enter your first name!</p>';
} else {
$fn = $_POST['first_name'];
}
//check for a flat no
if (empty($_POST['flat_no'])) {
$fln = FALSE;
$message .= '<p>You forgot to enter youe Flat No!</p>';
} else {
$fln = $_POST['flat_no'];
}
//check for a building name
if (empty($_POST['building_name'])) {
$bn = FALSE;
$message .= '<p>You forgot to enter the building name!</p>';
} else {
$bn = $_POST['building_name'];
}
if($ln && $fn && $fln && $bn) { //if everthings is ok.
//register the user in the database.
require_once ('connect.php'); // Connect to the db.
// make the query.
$query = "DELETE FROM Residents WHERE surname = '$ln' and first_name = '$fn' and flat_no = '$fln' and building_name = '$bn'";
$result = mysql_query ($query); //run the query.
if ($result) { // if it ran ok.
echo '<p><b>Record deleted!</b></p>';
exit(); // Quit the script
} else { // if it didnt run ok.
$message = '<p>Data could not be deleted due to a system error.</p><p>' . mysql_error() . '</p>';
}
mysql_close(); //Close the database connection.
} else {
$message .= '<p>Please try again.</p>';
}
// Print the message if there is one.
if (isset($message)) {
echo '<font color="red">', $message, '</font>';
}
?>
</body>
</html>
Im currently working on a residential database and working on the 'delete resident' page. Everything works and the correct reisdent gets deleted as wanted. The problem I have is that when the page loads up all of the "else" statements such as "you have forgot to enter your surname" appears when it shouldnt.
Can anyone help?
Regards
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Residents Database Admin User</title>
</head>
<body
style="background-image: url(file:///var/<img style="width: 121px; height: 153px;" alt=""
src="file:///var/ style="width: 357px; height: 99px;" alt=""
src="file:///var/ style="width: 299px; height: 99px;" alt=""
src="file:///var/<div style="text-align: center;"><img
style="width: 463px; height: 14px;" alt=""
src="file:///var/ <br>
<div style="text-align: left;">
<font size="+1"><span
style="text-decoration: underline; font-weight: bold; font-style: italic;">Search<br>
<br>
</span></font>
<table style="text-align: left; width: 50%;" border="1" cellspacing="2"
cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top;"><a href="buildingname.php"><img
style="width: 118px; height: 25px;" alt=""
src="file:///var/ <td style="vertical-align: top;"><a href="flatnumber.php"><img
style="width: 118px; height: 25px;" alt=""
src="file:///var/ <td style="vertical-align: top;"><a href="surname.php"><img
style="width: 118px; height: 25px;" alt=""
src="file:///var/ <td style="vertical-align: top;"><a href="viewresidents.php"><img
style="border: 0px solid ; width: 118px; height: 25px;" alt=""
src="file:///var/ </tr>
</tbody>
</table>
<div style="text-align: right;"><br>
</div>
<table
style="width: 28%; text-align: left; margin-right: auto; margin-left: 120px;"
border="1" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td style="vertical-align: top; text-align: center;"><a
href="register.php"><img style="width: 118px; height: 25px;"
alt="" src="file:///var/ <td style="vertical-align: top; text-align: center;"><a
href="delete.php"><img style="width: 118px; height: 25px;"
alt="" src="file:///var/ </tr>
</tbody>
</table><br>
</div>
</div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>Enter your information in the form below:</legend>
<p><b>Last Name:</b> <input type="text" name="surname" size="30" maxlength="30"
value="<?php if (isset($_POST['surname'])) echo $_POST['surname']; ?>" /></p>
<p><b>First Name:</b> <input type="text" name="first_name" size="15" maxlength="15"
value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
<p><b>Flat No:</b> <input type="text" name="flat_no" size="15" maxlength="15"
value="<?php if (isset($_POST['flat_no'])) echo $_POST['flat_no']; ?>" /></p>
<p><b>Building Name:</b> <input type="text" name="building_name" size="15" maxlength="15"
value="<?php if (isset($_POST['building_name'])) echo $_POST['building_name']; ?>" /></p>
<div align="centre"><input type="submit" name"submit" value="Delete Record"></div>
</form><!-- end of form -->
<?php # Scrtipt 6.6 - register.php
$page_title = 'Add New Entry';
$message = NULL; // create an empty new variable.
//check for a surname
if (empty($_GET['surname'])) {
$ln = FALSE;
$message .= '<p>You forgot to enter your surname!</p>';
} else {
$ln = $_GET['surname'];
}
//check for a first name
if (empty($_POST['first_name'])) {
$fn = FALSE;
$message .= '<p>You forgot to enter your first name!</p>';
} else {
$fn = $_POST['first_name'];
}
//check for a flat no
if (empty($_POST['flat_no'])) {
$fln = FALSE;
$message .= '<p>You forgot to enter youe Flat No!</p>';
} else {
$fln = $_POST['flat_no'];
}
//check for a building name
if (empty($_POST['building_name'])) {
$bn = FALSE;
$message .= '<p>You forgot to enter the building name!</p>';
} else {
$bn = $_POST['building_name'];
}
if($ln && $fn && $fln && $bn) { //if everthings is ok.
//register the user in the database.
require_once ('connect.php'); // Connect to the db.
// make the query.
$query = "DELETE FROM Residents WHERE surname = '$ln' and first_name = '$fn' and flat_no = '$fln' and building_name = '$bn'";
$result = mysql_query ($query); //run the query.
if ($result) { // if it ran ok.
echo '<p><b>Record deleted!</b></p>';
exit(); // Quit the script
} else { // if it didnt run ok.
$message = '<p>Data could not be deleted due to a system error.</p><p>' . mysql_error() . '</p>';
}
mysql_close(); //Close the database connection.
} else {
$message .= '<p>Please try again.</p>';
}
// Print the message if there is one.
if (isset($message)) {
echo '<font color="red">', $message, '</font>';
}
?>
</body>
</html>