Some post value record not saved in database table from dynamic created row table of front end

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 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;">
                        <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>                         
                    <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>
                $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>
                }     ?>    </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>
      $sql = mysqli_query($con,"SELECT * FROM consultant");
         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

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);			
$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]);


If you’re going to copy and paste from StackOverflow, at least bother to remove the vote counter at the start of the post.

its my own code! and I am the one who posted at stack over flow, yes i copy from that question but i am the owner of that question there is well. there is hardly one minute difference between both question publications

I’m betting that if you do the things that have already been suggested in your threads (some of which you have ‘liked’) - fix the logic mistakes, add validation logic, add error handing for the database statements that can fail, add duplicate data error detection, and execute each set of insert queries as part of a transaction, that you will find out why some of the queries are not working.


You need to narrow down exactly what is common between the entries that are not stored, in contrast to the entries which are stored correctly. You could log all your $_POST variables into a log file along with date and time so that, once you see an entry that has missing information, you can check in the log to see what data is being received, and attempt to identify a pattern.

Is the image relevant? Your question says that

and yet the image shows five procedures. Or is the image (which seems to contain a lot of personal information, to me, unless it’s all test data) the data that you are entering into your software, in which case I can’t see how it helps - we believe that you’re entering five rows and sometimes only storing four.

As above, though, some basic data validation and checking for errors might go a long way towards solving the issue.

1 Like

but if there is issue it should not been working for every record! why it happened very few times instead of all records. Yes i am going to add all these things which you suggested earlier

That depends on what the issue is, surely?

ok i am going to add validations on front end

That’s great, but you need it in the PHP back end code as well. In fact I’d suggest it would be more use to you in the PHP at the moment, to help you identify exactly what problem you need to be addressing in the front end code.

Data submitted to your web site can come from anywhere, not just your forms, links, or cookies, can be set to anything, and cannot be trusted. You need to trim, mainly so that you can detect if all white-space characters were entered, then validate all data on the server before using it. Doing this also helps detect programming mistakes in your client-side markup/code.

Client-side validation is a nicety for legitimate visitors. You already have this via the ‘required’ attributes. There’s no point in doing more than this in the client since you must validate the data on the server before using it.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.