When I click the checkbox, only the first row shows the text box.
Expected When I check the checkbox, the text box will show in that row.
When i click the submit button, it only inserts the data from the first row.
Example When I checked 3 boxes, it will insert the data from the first row 3 times.
How can I fix my code?
<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!
";
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') ");
}
}
?>