How can you send this kind of form to database with something like this
You registered your classmates John Doe and Peter Smith in one submission that is why they have the same dcode. While the rest is separate
$('#add-btn').click(function(){
const elem = ' <input type="text" name="dcode" hidden value="<?php echo(mt_rand(100000000,999999999)); ?>"><input class="form-control" type="text" name="lname[]" placeholder="Last Name" required><input class="form-control" type="text" name="fname[]" placeholder="First Name" required><input class="form-control" type="text" name="mname[]" placeholder="Middle Name" required><br>';
$('#add-btn').before(elem);
})
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" rel="stylesheet">
</head>
<body>
<form method="POST" action="classmate_insert.php">
<div class="form-group col-6 mx-auto m-5">
<label for="dependents">Classmates:</label>
<button id="add-btn" class="form-control btn-danger">Add</button><br>
<button type="submit" class="btn btn-primary float-right ">Submit</button>
</div>
</form>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js"></script>
</body>
<script type="text/javascript">
</script>
</html>