Hi,
in the "new order" page, i have to send duplicate field into MySQL
but i don't know how to send...
following is my problem:
I create two tables, one is order, another is product,and in the "new order" page, above is :
<td class="content"> <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="orderform" id="orderform">
<p>order num:
<input name="order_num" type="text" id="order_num" value="<?php echo ($row_rsOrdernum['MAX(order_num)']+1); ?>" size="6" maxlength="6" />
customer name:
<select name="cus_num" id="cus_num">
<?php
do {
?>
<option value="<?php echo $row_rsCusName['cus_num']?>"><?php echo $row_rsCusName['cus_name']?></option>
<?php
} while ($row_rsCusName = mysql_fetch_assoc($rsCusName));
$rows = mysql_num_rows($rsCusName);
if($rows > 0) {
mysql_data_seek($rsCusName, 0);
$row_rsCusName = mysql_fetch_assoc($rsCusName);
}
?>
</select>
order date:
<input name="order_date" type="text" id="order_date" value="<?php $date = date('Y-m-d') ;echo $date;?>" size="12" maxlength="10" />
enddate:
<input name="order_enddate" type="text" id="order_enddate" size="12" maxlength="10" />
total:<input name="order_total" type="text" id="order_total" size="8" maxlength="6" />
<input name="calculate" type="button" id="calculate" value="count" />
<input name="sendorder" type="submit" id="sendorder" value="send" />
</p>
the following is a for loop, and i wish they can send to the product
<?php for( $i=0 ; $i<30 ; $i++) { ?><p>
prod code:
<select name="prod_Pnum" id="prod_Pnum">
<?php
do {
?>
<option value="<?php echo $row_rsProdPname['prod_Pnum']?>"><?php echo $row_rsProdPname['prod_Pname']?></option>
<?php
} while ($row_rsProdPname = mysql_fetch_assoc($rsProdPname));
$rows = mysql_num_rows($rsProdPname);
if($rows > 0) {
mysql_data_seek($rsProdPname, 0);
$row_rsProdPname = mysql_fetch_assoc($rsProdPname);
}
?>
</select>
product spec:
<input name="prod_spec" type="text" id="prod_spec" size="18" maxlength="16" />
quantity:
<input name="prod_amount" type="text" id="prod_quantity" size="4" maxlength="4" />
price:
<input name="prod_price" type="text" id="prod_price" size="6" maxlength="4" />
subtotal:
<input name="sc[]" type="text" id="sc[]" size="6" maxlength="6" />
note:
<input name="prod_note" type="text" id="prod_note" size="8" maxlength="6" />
</p><?php } ?>
<input type="hidden" name="MM_insert" value="orderform">
</form>
First: i don't get how to make the button "calculate" work directly, because i don't
know how to check the duplicate field "quantity", "price" and when i click "calculate", the subtotal(s) and total will show up ...
Second:the insert behavior(to MySQL)
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "orderform")) {
$insertSQL = sprintf("INSERT INTO product (order_num, prod_Pnum, prod_spec, prod_quantity, prod_price, prod_note) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['order_num'], "int"),
GetSQLValueString($_POST['prod_Pnum'], "int"),
GetSQLValueString($_POST['prod_spec'], "text"),
GetSQLValueString($_POST['prod_quantity'], "int"),
GetSQLValueString($_POST['prod_price'], "int"),
GetSQLValueString($_POST['prod_note'], "text"));
mysql_select_db($database_conn_wh, $conn_wh);
$Result1 = mysql_query($insertSQL, $conn_wh) or die(mysql_error());
$insertGoTo = "order_newSuccess.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "orderform")) {
$insertSQL = sprintf("INSERT INTO ordert (order_num, cus_num, order_date, order_enddate, order_total) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['order_num'], "int"),
GetSQLValueString($_POST['cus_num'], "int"),
GetSQLValueString($_POST['order_date'], "date"),
GetSQLValueString($_POST['order_enddate'], "date")
GetSQLValueString($_POST['order_total'], "int"));
mysql_select_db($database_conn_wh, $conn_wh);
$Result1 = mysql_query($insertSQL, $conn_wh) or die(mysql_error());
$insertGoTo = "order_newSuccess.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
it's the main problem that i don't know how to insert the duplicate field in the for loop.
how should i do ?😕 😕 so confused..
Thanks for any help