ユーザーが必要に応じてフィールドの数を増やしたり追加したりできるフォームがあります。
フィールドが正常に追加されています.....
このために私はjavascriptを使用し、コードはここにあります..
<script type="application/javascript">
var counter3 = 0;
function addAuthor() {
    // Get the main Div in which all the other divs will be added
    var mainContainer = document.getElementById('Author');
    // Create a new div for holding text and button input elements
    var newDiv = document.createElement('div');
    // Create a new text input
    var newText = document.createElement('input');
    newText.type = "text";
    //var i = 1;
    newText.name = "Author[]";
    //newText.value = counter3 + 2 + ". ";
    //Counter starts from 2 since we already have one item
    //newText.class = "input.text";
    // Create a new button input
    var newDelButton = document.createElement('input');
    newDelButton.type = "button";
    newDelButton.value = "-";
    // Append new text input to the newDiv
    newDiv.appendChild(newText);
    // Append new button input to the newDiv
    newDiv.appendChild(newDelButton);
    // Append newDiv input to the mainContainer div
    mainContainer.appendChild(newDiv);
    counter3++;
    //i++;
    // Add a handler to button for deleting the newDiv from the mainContainer
    newDelButton.onclick = function() {
        mainContainer.removeChild(newDiv);
        counter3--;
    }
}
</script>
ここにフォームがあります..
<form method="post" action="">
    <input type = "text" name="Author[]" />
    <input type="button" value="+" id="Authorbutton" onclick="addAuthor()" />
    <input type="submit" value="submit" name="submit">
    </form>
私はデータをデータベースに保存するためにphpとmysqlクエリを使用しています..コードコードは..
<?php
if(isset($_POST['submit']))
{
$authors = $_POST['Author'];
foreach($authors as $author) 
{
    $sql=mysql_query("INSERT INTO test (number, type) VALUES ('{$_POST['type']}','{$author}')");
    if (!$sql){
       die('Error: ' . mysql_error());
    }
//endforeach;
}
}
?>
しかし問題は、データがデータベースに正しく保存されないことです...
データベースの最初のフィールドのみを保存しますが、2番目、3番目、4番目などは保存しません...
助けて ........