<html>
<body>
<form method="POST" action="">
<label>Select your Category:</label>
<input type="text" name="category" id="cat-list"/>
</br>
<label> Display Name:</label>
<input type="text" name="display_name" id="displayname"/>
</br>
<label> Select your Subcategory:</label>
<input type="text" name="pagename" id="subcat-list"/>
</br>
<label>Set Order</label>
<select name="privilage" id="privilage" required>
<option value="">Select</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</br>
<button type="button" name="add" id="savebutton"><i class="icon-check-sign" aria-hidden="false"></i>Add</button>
<table id="pTable" class="table table-hover" width="100%" cellspacing="0" style="border: 1px; height:10px;" >
<thead style="background-color:#CCE5FF">
<tr id="row">
<th>Category</th>
<th>DisplayName</th>
<th>Subcategory</th>
<th>Order</th>
<th colspan=2>Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<button type="submit" name="import" > Import Database</button>
</form>
<script src=" https://code.jquery.com/jquery-3.2.1.js" type="text/javascript"></script>
<script>
var i=0;
currentRow = null;
$("button#savebutton").click(function(){
var cat = $("#cat-list").val();
var display = $("#displayname").val();
var subcat = $("#subcat-list").val();
var order = $("#privilage").val();
i++;
//Inserting first row to the table with edit and delete button
var new_row = "<tr id='row"+i+"' class='info'><td class='cat'>" + cat + "</td><td class='display'>" + display + "</td><td class='type'>" + subcat +"</td><td>"+order +"</td><td><span class='editrow'><a class='fa fa-edit' href='javascript: void(0);'>Edit</a></span></td><td><span class='deleterow'><a class='glyphicon glyphicon-trash' href=''>Delete</a></span></tr>";
//Appending the new row to the table
if(currentRow){
$("table tbody").find($(currentRow)).replaceWith(new_row);
currentRow = null;
}
else{
$("table tbody").append(new_row);
}
});
//Editing the row entered
$(document).on('click', 'span.deleterow', function () {
$(this).parents('tr').remove();
return false;
});
//Deleting the row
$(document).on('click', 'span.editrow', function () {
currentRow= $(this).parents('tr');
});
</script>
<?php
require('connection1.php');
echo 123;
if(isset($_POST['import'])){
$query=mysqli_query($db,"INSERT INTO selectedpages(display_name,category,pagename,privilage) values('".$_POST['display_name']."','".$_POST['category']."','".$_POST['pagename']."','".$_POST['privilage']."')") or die(mysqli_error($db));
if($query>0){
echo "Success";
}
else {
echo "failed";
}
}
?>
Content: The code is to enter the multiple row values to the database,but the problem is only the last row value is entering into database.If there are 3 rows ,only the third row details entering into the database.Firstly, the form having a add button and an import button.Add button is used for adding the rows and then have to click the import button for entering these row values to the database.