通过jquery动态输入并提交到mysql表

I need some advice in the following code.

var count = 1;
$(function(){
    $('#addmore').click(function(){
        count += 1;
        $('ul').append("<li><input type='text' id='hd"+count+"' name='hd"+count+"' value='heading' onClick='this.select();'> <input type='text' id='amount"+count+"' name='amount"+count+"' value='amount' onClick='this.select();'></li>");
//      return false;
    });
});

what exact php code should i use to submit all the input into my test table of mysql.

<button id="addmore">+</button>
<form id="myForm" name="myForm" action="" method="post" onSubmit="return false;">
<ul>
    <li><input type="text" id="hd1" name="hd1" value="heading" onClick="this.select();">
    <input type="text" id="amount1" name="amount1" value="amount" onClick="this.select();"></li>
</ul>
<input type="submit" value="Submit" id="submit" name="submit">
</form>

<?php
if(isset($_POST['submit'])){

echo "h";
};
?>

keeping in mind that i've test table with two fields 'heading' and 'amount'.


if(isset($_POST['submit'])){
    foreach($_POST['hd'] as $hds){
        echo $hds;
        mysqli_query($con,"INSERT INTO test (hdg) VALUES ($hds)");
    };
};

and its not adding data into my table

Use [] for the name attributes instead of the numbers:

<li><input type="text" id="hd1" name="hd[]" value="heading" onClick="this.select();">

On the server-side you will have an array of values.

$hd = $_POST['hd']; // Returns an array