I have a dynamic form which allows to add multiple textboxes. While saving the data in the database, it also saves an additional empty extra row. Could you help to find the issue?
HTML:
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<input name="skill[]" type="text" class="form-control" placeholder="Skill name, e.g. HTML">
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<div class="input-group">
<input name="percent[]" type="text" class="form-control" placeholder="Skill proficiency, e.g. 90">
<span class="input-group-addon">%</span>
</div>
</div>
</div>
<div class="col-xs-12 duplicateable-content">
<div class="item-block">
<div class="item-form">
<button class="btn btn-danger btn-float btn-remove"><i class="ti-close"></i></button>
<div class="row">
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<input name="skill[]" type="text" class="form-control" placeholder="Skill name, e.g. HTML">
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<div class="input-group">
<input name="percent[]" type="text" class="form-control" placeholder="Skill proficiency, e.g. 90">
<span class="input-group-addon">%</span>
</div>
</div>
</div>
</div>
</div>
</div>
Here is my php to save the data input:
for ($i = 0; $i < count($_POST["skill"]); $i++) {
$skill = $_POST["skill"][$i];
$percent = $_POST["percent"][$i];
$sql = "insert into tb_skill (skills,percent,user_id) values
('$skill', '$percent', '$_SESSION[id]')";
mysqli_query($con, $sql);
}