i have one billing form which stored information into two mysql table. first table storing information correctly, but 2nd table which stored information from dynamic section missing some record occasionally. as shown in attached image, enter image description here,there are 5 procedure , but only 4 are stored in database, one is missing. I entered almost 100 record per day and this issue is happened with only one or two record in one day. Can any one suggest chnages in below code which ensure all enteries have been added in database. below is my code form code
<div class="row"> <div class="col-lg-4"> <div class="form-group">
<label>MR No:</label> <input type="text" name= "mrno" id= "mrno" value="<?php echo $aaa1; ?>" class="form-control" Required>
</div> </div>
<div class="col-lg-4"> <div class="form-group">
<label>Name:</label> <input type="text" name= "name1" id= "name1" value="<?php echo $ccc1; echo ' '; echo $ddd1; ?>" class="form-control" Required>
</div> </div>
<div class="col-lg-4"> <div class="form-group">
<label>Age :</label> <input type="text" name= "age1" id= "age1" value="<?php echo $eee1; ?>" class="form-control">
</div> </div></div>
<div class="row"> <div class="col-lg-4"> <div class="form-group">
<label>Gender:</label> <input type="text" name="gender1" id='gender1' value="<?php echo $fff1; ?>" class="form-control">
</div> </div>
<div class="col-lg-4"> <div class="form-group">
<label>Mobile:</label> <input type="text" name= "mobno" id= "mobno" value="<?php echo $ggg1; ?>" class="form-control" Required>
</div> </div>
</div></div>
<div class="row">
<div class="col-lg-4"> <div class="form-group">
<label>Bill Date:</label> <input type="date" value = "<?php echo date("Y-m-d"); ?>" name= "bildate" id= "bildate" class="form-control" readonly style="background-color: #3fbbc0;">
</div> </div></div>
<table class="table table-bordered">
<thead class="table-success" style="background-color: #3fbbc0;">
<tr>
<th width="15%"><center>Type</th>
<th width="15%"><center>Service</th>
<th width="10%"><center>Machine</th>
<th width="10%"><center>Consultant</th>
<th width="5%"><center>Qty</th>
<th width="10%"><center>Rate</th>
<button type="button" class="btn btn-sm btn-success" onclick="BtnAdd()">Add Item</button>
</th>
</tr>
</thead>
<tbody id="TBody">
<tr id="TRow" class="d-none">
<td><Select class="country form-control text-end" name="country[]" id = "country" required>
<option value=""> Select Type</option>
<?php
include('db1.php');
$query = "select * from country";
// $query = mysqli_query($con, $qr);
$result = $con->query($query);
if ($result->num_rows > 0) {
while ($row = mysqli_fetch_assoc($result)) {
?>
<option value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></option>
<?php
}
} ?> </select> </td>
<td><Select class="state form-control text-end" name="state[]" id = "state" required>
<option value="">select Service</option></select></td>
<td><Select class="city form-control text-end" name="city[]" id = "city" required onchange="GetDetail(this.closest('tr'))" >
<option value="">Select Machine</option></select></td>
<td><Select class="form-control text-end" name="docname[]" id="iii" required onfocus="Calc(this);">
<option value="">Select Consult</option>
<?php
include('db.php');
$sql = mysqli_query($con,"SELECT * FROM consultant");
while($row=mysqli_fetch_array($sql))
{
echo '<option value="'.$row['consultant_name'].'">'.$row['consultant_name'].'</option>';
} ?> </select></td>
<td><input type="text" class="qty form-control text-end" name="qty[]" id="ccc" onfocus="Calc(this);"></td>
<td><input type="text" class="price form-control text-end" name="price1[]" id="ddd" onfocus="Calc(this);" readonly style="background-color: #3fbbc0;"></td>
<td class="NoPrint"><button type="button" class="btn btn-success" style="line-height: 1;" onclick="BtnDel(this)">x</button></td>
</tr> </tbody> </table>
Processing code
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
if($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit']))
{
// getting all values from the HTML form
$mrno = $_POST['mrno'];
$name1 = $_POST['name1'];
$age1 = $_POST['age1'];
$mobno = $_POST['mobno'];
$country = $_POST['country'];
$state = $_POST['state'];
$city = $_POST['city'];
$docname= $_POST['docname'];
$qty = $_POST['qty'];
$price1 = $_POST['price1'];
}
// using sql to create a data entry query
// using sql to create a data entry query
$sqlInsert ="INSERT INTO iap3 (mrno, name1, age1, mobno) VALUES (?,?,?,?)";
$queryiap3 = $con->prepare($sqlInsert);
$queryiap3->bind_param('ssss', $mrno, $name1, $age1, $mobno);
$queryiap3->execute();
$last_id = $queryiap3->insert_id;
$sqliap4 = "INSERT INTO iap4 (pid, country, state, city, docname, qty, price1)
VALUES (?,?,?,?,?,?,?)";
$queryiap4 = $con->prepare($sqliap4);
for ($i = 0; $i < count($city); $i++) {
$queryiap4->bind_param('sssssss', $last_id, $country[$i], $state[$i], $city[$i], $docname[$i], $qty[$i], $price1[$i]);
$queryiap4->execute();
}

?>