Hi,
I have a script I am writing and am having issues with inserting results into the database. It is doing the INSERT but not inserting all the values. Any suggestions?
Here is the code:
<?php # process_form.php
include ('./includes/menu_header.html');
include ('./db/db.php');
$page_title = 'Process Menu Form';
$query = "SELECT * from dishes";
$result = @mysql_query ($query);
if ($result) { // If query ran ok
$oid = $_POST['order_id'][$ix];
$sel = $_POST['selection'][$i];
$d1 = $_POST['dish_id'];
$dn = $_POST['dish_name'];
$od_qty = $_POST['od_qty'][$i];
$price = $_POST['dish_price'];
// Check if form submitted
if (isset($_POST['submitted'])){
$errors = array(); // Initialize error array.
//check for required data.
if (isset($_POST[$qty]) || trim($_POST[$qty]) != '') {
}
// Check for TOTAL
if (empty($_REQUEST['od_total'])) {
$errors[] = 'You did not order any dishes.';
} else {
$tot = trim($_REQUEST['od_total']);
}
if (empty($errors)) { // If everything's okay.
// Print the results.
echo '<p id="process">Your TOTAL ORDER is: ' . $_REQUEST['od_total'] . ' </p>
<p><a href="customer.php"><img src="images/proc_ord_but.gif" border="0"></a></p>
<p id="content">You ordered:</p>
<table id="content">';
echo '<tr>';
foreach ($_POST['od_qty'] as $val)
if ($val != NULL) {
// foreach ($_POST['selection'] as $sel)
echo '<td> ' .$val.' ' .$sel. '</td></tr>';
$query = "INSERT INTO order_details (od_id, order_id, dish_id, od_qty, order_date, dish_price) VALUES ('', '$oid', '$d1', '$val', NOW(), '$price')";
$result = @mysql_query ($query); // Run the query
}
}
echo '</table>';
echo '<p>';
// This is here for testing purposes to see what is being passed.
foreach($_POST as $key => $value) {
echo $key . ' has a value of: ' . $value . "<br>\n";
}
echo '</p>';
} else { // Invalid submitted values.
echo '<h1 id="mainhead">Error!</h1>
<p class="error">We did not receive a total for your order.</p><p><br /></p>';
}
}
mysql_close($dbc);
?>