单击复选框时,只有第一行显示文本框。
预期当我选中该复选框时,文本框将显示在该行中。
当我点击提交按钮时,它只会插入第一行的数据。
示例当我选中3个框时,它会将第一行的数据插入3次。
如何修复我的代码?
<script type="text/javascript">
function changeText(codeasset){
if(codeasset.checked){
document.getElementById('hotStuff').innerHTML = '<input type="text" id="hotStuff" style="width: 150px;" />';
}else {
document.getElementById('hotStuff').innerHTML='';
}}
</script>
<?php
$assets_supplier_query = mysql_query("SELECT * FROM supplier_assets WHERE status = '0' AND supplier_id = '$supplier_id'");
while ($get_supplier_asset = mysql_fetch_array($assets_supplier_query))
{
$asset_code = $get_supplier_asset['asset_code'];
$asset_qty = $get_supplier_asset['supply_quantity'];
$asset_query = mysql_query("SELECT * FROM ref_assetmodel WHERE modelID = '$asset_code' ");
$get_asset = mysql_fetch_array($asset_query);
$asset_model = $get_asset['assetModel'];
$specifications = $get_asset['specifications'];
$category_id = $get_asset['categoryID'];
$type_id = $get_asset['typeID'];
$category_query = mysql_query("SELECT * FROM ref_assetcategory WHERE categoryID = '$category_id' ORDER BY categoryID");
$get_category = mysql_fetch_array($category_query);
$category = $get_category['assetCategory'];
$type_query = mysql_query("SELECT * FROM ref_assettype WHERE typeID = '$type_id' ");
$get_type = mysql_fetch_array($type_query);
$type = $get_type['assetType'];
?>
<form action="../process/approve_supplies_process.php" method="post" name="supplier">
<td><input type="checkbox" id="codeasset" name="supply[]" onclick="changeText(this)" value="<?php echo $asset_code ?>"> </td>
<td name="supply[]"><?php echo $type; ?></td>
<td name="supply[]"><?php echo $asset_model; ?></td>
<td name="supply[]"><?php echo $asset_qty; ?></td>
<td name="supply[]" id="hotStuff" value="<?php echo $asset_code ?>"></td>
<?php
}
?>
<tr>
<td align="center"><input type="submit" class="edit_butt" name="action" value="Submit" onclick=""></td>
<input type="hidden" name="supplier_id" value="<?php echo $supplier_id; ?>">
</tr>
</form>
<?php
$asset_code = $_POST['asset_code'];
$categoryID = $_POST['category_id'];
$type_id = $_POST['type_id'];
$supplier_id = $_POST['supplier_id'];
date_default_timezone_set('Asia/Manila');
$inventoryDate= date("Y-m-d");
if(isset($_POST['supply'])){
foreach ($_POST['supply'] as $_value)
{
echo "Box #{$_value} was selected!\n";
mysql_query("INSERT INTO ref_inventory(inventoryDate, categoryID, typeID, modelID, serialNumber, qrCode, is_owned, supplier_id)
VALUES('$inventoryDate', '$categoryID', '$type_id', '$asset_code', '954', '', 1, '$supplier_id') ");
}
}
?>