I have a form to upload images to a table in mysql. I am getting following errors:
"Please enter the cashregister's name!
The file has been uploaded!
The script is a follows:
<?php
require_once ('dbcompstore.php'); // Connect to the database.
if (isset($_POST['submit'])) { // Handle the form.
// Create a function for escaping the data.
function escape_data ($data) {
global $dbc; // Need the connection.
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_escape_string($data);
} // End of function.
// Check for a cashreg name.
if (!empty($_POST['cr_name'])) {
$pn = escape_data($_POST['cr_name']);
} else {
$pn = FALSE;
echo '<p><font color="red">Please enter the cashregister\'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 a price.
if (is_numeric($_POST['price'])) {
$p = $_POST['price'];
} else {
$p = FALSE;
echo '<p><font color="red">Please enter the cashregister\'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>';
}
// Add the print to the database.
$query = "INSERT INTO crimages ( cr_name, price, description, image_name) VALUES ('$pn', '$p', '$d', '$i')";
if ($result = @mysql_query ($query)) { // Worked.
echo '<p>The cash reg 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>';
}
?>
<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 print to the catalog:</legend>
<p><b>Cash Register:</b> <input type="text" name="print_name" size="30" maxlength="60" /></p>
<p><b>Image:</b> <input type="file" name="image" /></p>
<?php
mysql_close(); // Close the database connection.
?>
<p><b>Price:</b> <input type="text" name="price" size="10" maxlength="10" /><br /><small>Do not include the dollar 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>
I have the upload file in same directory as pages- realise not that secure but for testing puposes. I do not understand why the name error is happening, and why not processing although says file uploaded.
Charles