All pastes #226278 Raw Edit

Someone

public text v1 · immutable
#226278 ·published 2006-10-28 11:50 UTC
rendered paste body
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<meta http-equiv="content-type" content="text/html"; charset=iso-8859-1" />
<title>Add a Product</title>
</head>
<body>
<?php
//This page allows the administrator to add a product.

require_once ('mysql_connect.php'); //Connect to the database.

if (isset($_POST['submit'])) { //Handle the form.

//Validate the product name, image, size, price and description.

//Check for a product name.
if (!empty($_POST['name'])) {
$pn = escape_data($_POST['name']);
} else {
$pn = FALSE;
echo '<p><font color="red">Please enter the product\'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'],
"images/{$_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 a size (not required).
if (!empty($_POST['size'])) {
$s = escape_data($_POST['size']);
} else {
$s = '<i>Size information not available.</i>';
}

//Check for a price.
if (is_numeric($_POST['price'])) {
$p = $_POST['price'];
} else {
$p = FALSE;
echo '<p><font color="red">Please enter product\'s price!</font></p>';
}

//Check for a description (not required).
if (!empty($_POST['description'])) {
$d = escape_data($_POST['description']);
} else {
$d = '<i>No description available.</i>';
}

if ($pn && $p) {

// Add the print to the database.
$query = "INSERT INTO product (name, price, size, description, image_name)
VALUES ($pn, $p, '$s', '$d', '$i')";
if ($result = @mysql_query ($query)) {//Worked.
echo '<p>The print 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 product to the catalog:</legend>

<p><b>Product Name:</b><input type="text" name="name" size="30" maxlength="60"/></p>

<p><b>Image:</b><input type="file" name="image"/></p>

<p><b>Size: </b> <input type="text" name="size" size="30" maxlength="60" /></p>

<p><b>Price: </b> <input type="text" name="price" size="10" maxlength="10" /><br /><small>Do not include the pound sign or commas.</small></p>

<p><b>Description: </b> <textarea name="description" 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>