我试图获取动态生成的表的值并将它们插入到数据库中。 这就是我现在所拥有的:
JS:注意所有值都有效,它们会被添加到表中。当按下按钮(而不是HTML代码)时,将调用此函数。
function addRow1( price ) {
var dish = document.getElementById( "cmbDish" );
var amount = document.getElementById( "txtAmount" ).value;
if(amount == "" || amount == "0"){
amount = "1";
}
var table = document.getElementById( "datatable" );
var comments = document.getElementById( 'txtComments' );
var subt = amount * price;
var rowCount = table.rows.length;
var row = table.insertRow( rowCount );
row.insertCell( 0 ).innerHTML = '<input name="fdish[]" style="border:none; background-color:transparent; text-align:center; width:100%" disabled value=' + dish.value + '>';
row.insertCell( 1 ).innerHTML = '<input name="fcomment[]" style="border:solid; background-color:transparent; text-align:center; width:100%" value=' + comments.value + '>';
row.insertCell( 2 ).innerHTML = '<input type="text" name="famount[]" style="border:solid; background-color:transparent; text-align:center; width:100%" value=' + amount + '>';
row.insertCell( 3 ).innerHTML = '<input name="fprice[]" style="border:none; background-color:transparent; text-align:center; width:100%" disabled value= $' + price + '>';
row.insertCell( 4 ).innerHTML = '<input name="fsubtotal[]" style="border:none; background-color:transparent; text-align:center; width:100%" disabled value= $' + subt + '>';
row.insertCell( 5 ).innerHTML = '<input type="button" value = "Delete" onClick="Javacsript:deleteRow1(this)">';
}
&#13;
HTML / PHP:注意结尾处的按钮是发出POST的按钮
<form id="frmOrder" name="frmOrder" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>#Order" >
<div id="data">
<h2>List:</h2>
<table id="datatable" border="1" cellpadding="2" width="977">
<tr>
<td width="193"><h4 align="center">Dish</h4></td>
<td width="300"><h4 align="center">Comments</h4></td>
<td width="117"><h4 align="center">Amount</h4></td>
<td width="100"><h4 align="center">Price</h4></td>
<td width="119"><h4 align="center">SubTotal</h4></td>
<td width="140"><h4 align="center">Actions</h4></td>
</tr>
</table>
<br/>
</div>
<ul class="actions">
<p align="center"><input type="submit" class="button special" id="btnplaceOrder" name="btnplaceOrder" value="Place Order" /></p>
</ul>
</form>
如何从表中获取所有值并将它们插入到数据库表中。我已经使用所有字段创建了数据库
我试过这个:
if(!empty($_POST['btnplaceOrder'])&&$_POST["btnplaceOrder"]!=""){
foreach($_POST['fdish'] as $key => $value){
$dish = $_POST["fdish"][$key];
$comment = $_POST["fcomment"][$key];
$amount = $_POST["famount"][$key];
$price = $_POST["fprice"][$key];
$res = $object->do_query("INSERT into table(Id_order, Id_menu, amount, price, comment) values (1', '$dish', '$amount', '$price', '$comment')");
}
}
但是没有工作,没有错误,所以我不知道它有什么问题
答案 0 :(得分:0)
<强>解决强>
我将属性disabled
更改为readOnly
。我忘了disabled
属性阻止POST并且什么都不发送