this is most likely a newbie problem that i am having. i have a form which submits data to a mysql table the problem that i am having is that the form will not submit the data it keeps on asking for the meals name like the entry box is blank but its not. the code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20 ... tional.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 Print</title>
</head>
<body>
<?php
require_once ('../../mysql_connect.php'); // Connect to the database.
if (isset($_POST['submit'])) { // Handle the form.
// Check for a meals name.
if (!empty($_POST['meal_name'])) {
$pn = escape_data($_POST['meal_name']);
} else {
$pn = FALSE;
echo '<p><font color="red">Please enter the meals 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 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 the meals 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>';
}
// Validate the contents.
if ($_POST['content'] == 'new') {
// If it's a new content, add the content to the database.
$query = 'INSERT INTO contents (contents_id, nuts, dairy, meat_type) VALUES (NULL, ';
if (!empty($_POST['nuts'])) {
$query .= "'" . escape_data($_POST['nuts']) . "', ";
} else {
$query .= 'NULL, ';
}
if (!empty($_POST['dairy'])) {
$query .= "'" . escape_data($_POST['dairy']) . "', ";
} else {
$query .= 'NULL, ';
}
// Check for a last_name.
if (!empty($_POST['meat_type'])) {
$query .= "'" . escape_data($_POST['meat_type']) . "')";
$result = @mysql_query ($query); // Run the query.
$a = @mysql_insert_id(); // Get the artist ID.
} else {
$a = FALSE;
echo '<p><font color="red">Please enter the meat type last name!</font></p>';
}
} elseif ( ($_POST['content'] == 'existing') && ($_POST['existing'] > 0)) {
$a = $_POST['existing'];
} else {
$a = FALSE;
echo '<p><font color="red">Please enter or select the meals content</font></p>';
}
if ($pn && $p && $a) {
$query = "INSERT INTO meal (contents_ID, meal_name,image_name, size, price, description ) VALUES ('".$a."','".$pn."', '".$p."', '".$s."', '".$i."', '".$d."')";
$result = mysql_query($query) or die(MySQL_Error());
echo '<p>The meal 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 meal to the catalog:</legend>
<p><b>meal Name:</b> <input type="text" name="print_name" size="30" maxlength="60" /></p>
<p><b>Image:</b> <input type="file" name="image" /></p>
<p><b>Artist:</b>
Existing <input type="radio" name="content" value="existing" />
<select name="existing"><option>Select One</option>
<?php // Retrieve all the artists and add to the pull-down menu.
$query = "SELECT contents_id, CONCAT(meat_type, ', ', nuts) AS name FROM contents ORDER BY meat_type ASC";
$result = @mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
echo "<option value=\"{$row['contents_id']}\">{$row['name']}</option>\n";
}
mysql_close(); // Close the database connection.
?>
</select><br />
New <input type="radio" name="content" value="new" />
nuts: <input type="text" name="first_name" size="10" maxlength="30" />
dairy: <input type="text" name="middle_name" size="10" maxlength="30" />
meat_type: <input type="text" name="last_name" size="20" maxlength="30" />
</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 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>
form problems
Moderator: General Moderators