当书中有许多作者时,如何插入书中的数据时我有问题,如何在没有多余数据的情况下将其插入我的数据库中,这是我获取作者信息的代码,但是我如何将其插入一个书中行?或任何解决我的问题的方法
<input type="text" required name="author[]" placeholder="Author" class="form-control name_list" />
<button type="button" name="add" id="add" class="btn btn-success">Add More</button>
<script type="text/javascript">
$(document).ready(function(){
var i=1;
var maxfield = 2;
$('#add').click(function(){
if (i < maxfield) {
i++;
$('#dynamic_field').append('<tr id="row'+i+'"><td><input type="text" name="author[]" required placehold="Author" class="form-control name_list" /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');
}
});
$(document).on('click', '.btn_remove', function(){
var button_id = $(this).attr("id");
$('#row'+button_id+'').remove();
i--;
});
$('#submit').click(function(){
$.ajax({
url:"addingbook.php",
method:"POST",
data:$('#add_name').serialize(),
success:function(data)
{
alert(data);
$('#add_name')[0].reset();
window.location.href = 'book.php';
}
});
});
});
$number = count($_POST["author"]);
if($number > 0)
}
for($i=0; $i<$number; $i++)
{
if(trim($_POST["author"][$i] != ''))
{
$sql = "INSERT INTO book(title, author, publisher, publishdate)VALUES('$title', '".mysqli_real_escape_string($connect, $_POST["author"][$i])."', '$publisher', , '$publishdate')";
$insert = mysqli_query($connect, $sql);
}}}