I really hope someone can help it's been driving me nuts, the code I have is below in a file called add_home.php.
Thanks in advance
Kat
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Add a Home</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php # Script - add_home.php
// This page allows the administrator to add a home (product).
require_once ('../../mysql_connect.php'); // conect to the database.
if (isset($_POST['submit'])) { // Handle the form.
// Validate the home_name, category, year, berths, dimensions, axle, price and general_details.
//Check for a home name.
if (!empty($_POST['home_name'])) {
$hn = escape_data($_POST['home_name']);
} else {
$hn = FALSE;
echo '<p><font color="red">Please enter the home\'s name!</font></p>';
}
// Check for an image (not required).
if (is_uploaded_file ($_FILES['image']['tmp_name'])) {
if (move_uploaded_file($_FILES['image']['tmp_name'],
"../../uploads/{$_FILES['image']['name']}")) { // Move the file over.
echo '<p>The file has been uploaded!</p>';
} else { // Couldn't move the file over.
echo '<p><font color="red">The file could not be moved.</font></p>';
$i = '';
}
$i = $_FILES['image']['name'];
} else {
$i = '';
}
// Check for category
if(!empty($_POST['category'])) {
$c = escape_data($_POST['category']);
} else {
$c = FALSE;
echo '<p><font color="red">Please enter the home\'s category!</font></p>';
}
// Check for a year
if(!empty($_POST['year'])) {
$y = escape_data($_POST['year']);
} else {
$y = FALSE;
echo '<p><font color="red">Please enter the home\'s year</font></p>';
}
// Check for berths
if(!empty($_POST['berths'])) {
$b = escape_data($_POST['berths']);
} else {
$b = FALSE;
echo '<p><font color="red">Please enter the home\'s berth</font></p>';
}
// Check for dimensions
if(!empty($_POST['dimensions'])) {
$d = escape_data($_POST['dimensions']);
} else {
$d = FALSE;
echo '<p><font color="red">Please enter the home\'s dimensions</font></p>';
}
// Check for axle type
if(!empty($_POST['axle'])) {
$a = escape_data($_POST['axle']);
} else {
$a = FALSE;
echo '<p><font color="red">Please enter the home\'s axle type</font></p>';
}
// Check for a price
if(is_numeric($_POST['price'])) {
$p = $_POST['price'];
} else {
$p = FALSE;
echo '<p><font color="red">Please enter the home\'s axle type</font></p>';
}
// Check for a general description (not required).
if (!empty($_POST['general_details'])) {
$g = escape_data($_POST['general_details']);
} else {
$g = '<i>No description available.</i>';
}
if ($hn && $c && $y && $b && $d && $a && $p) {
// Add the home to the database.
$query = "INSERT INTO homes(exterior_name, home_name, category, year, berths, dimensions, axle, price, general_details)
VALUES('$i', '$hn', '$c', '$y', '$b', '$d', '$a', '$p', '$g')";
if ($result = @mysql_query ($query)) { // Worked.
echo '<p>The home has been added.</p>';
} else { // If the query did not run OK.
echo '<p><font color="red">Your submission could not be processed due to a system error.</font></p>';
}
} else { // Failed a test.
echo '<p><font color="red">Please click "back" and try again.</font></p>';
}
} else { // Display the form.
?>
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="524288">
<fieldset><legend>Fill out the form to add a home to the catalog:</legend>
<p><strong>Home Name:</strong> <input type="text" name="home_name" size="30" maxlength="40"></p>
<p><strong>Image:</strong> <input type="file" name="image"></p>
<p><strong>Category:</strong>
<select name="category" id="category">
<option value="New Home" selected>New Home</option>
<option value="Used Home">Used Home</option>
</select>
</p>
<p><strong>Year:</strong> <input type="text" name="year" size="4" maxlength="4"></p>
<p><strong>Berths:</strong> <input type="text" name="berths" size="2" maxlength="2"></p>
<p><strong>Dimensions:</strong> <input type="text" name="dimensions" size="30" maxlength="100"></p>
<p><strong>Axle:</strong> <input type="text" name="axle" size="20" maxlength="20"></p>
<p><strong>Price:</strong> <input type="text" name="price" size="10" maxlength="10"><br><small>Do not include the pound sign or comma.</small></p>
<p><strong>General Details:</strong> <textarea name="general_details" cols="40" rows="5"></textarea></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit"></div>
</form><!-- End of Form -->
<?php
} //End of main conditional.
?>
</body>
</html>Code: Select all
Field Type Null Default
home_id int(3) No
exterior_name varchar(60) Yes NULL
home_name varchar(40) No
category varchar(20) No
year year(4) No 0000
berths smallint(2) No 0
dimensions varchar(100) No
axle varchar(20) No
price decimal(6,2) No 0.00
general_details text Yes NULL
interior_name varchar(60) Yes NULL
interiordetail_name varchar(60) Yes NULLIndexes:
Code: Select all
Keyname Type Cardinality Field
PRIMARY PRIMARY 0 home_id
home_name INDEX None home_name
category