foreach
データベースに複数のデータを挿入するにはどうすればよいですか。js関数で行を追加および削除するために使用される
ドロップダウンメニューがあります。form
新しい行(フォームに追加)のデータをデータベースに挿入したいと思います。
これは私のフォームです:
<form action="insert.php" method="POST">
<input type="button" value="Add Row" onClick="addRow('tableID')"/>
<input type="button" value="Delete Row"
onClick="deleteRow('tableID')"/>
<table class="table" bgcolor="#CCCCCC">
<thead>
<tr>
<td></td>
<td><center>Item Description</center></td>
<td><center>Price (RM)</center></td>
<td><center>Month</center></td>
<td><center>Amount (RM)</center></td>
</tr>
</thead>
<tbody id="tableID">
<tr>
<td><input type="checkbox" name="chk"></td>
<td>
<select name="item_description">
<option value="deposit">Deposit</option>
<option value="rental">Rental</option>
<option value="stamp">Stamp Duty</option>
<option value="process">Process Fee</option>
<option value="ap">AP</option>
</select>
</td>
<td><input id="price" name="price" type="text"></td>
<td><input id="month" name="qty" type="text"></td>
<td><input id="amount" name="amount" type="text"></td>
</tr>
</tbody>
</table>
</form>
これは私の挿入クエリです:
<?php
//some connection code here
if(isset($_POST['submit']))
{
$item = array(
'item_description' => '',
'price' => '',
'qty' => '',
'amount' => '',
);
foreach ($item as $key => $value){
$value = $_POST[$key];
}
}
$last_insert_payment_id=mysql_insert_id();
$sql1="INSERT INTO payment_item (payment_id, payment_item_id, item_description, price, qty, amount)
VALUES
('$last_insert_payment_id','NULL','$_POST[item_description]','$_POST[price]','$_POST[qty]','$_POST[amount]')";
if (!mysql_query($sql1,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
?>
誰かが私がこれを理解するのを手伝ってくれることを願っています。ありがとうございました。