PHP只读取动态创建的输入数组的第一个值


PHP only read the first value of input array dynamic created

很抱歉英语不好,我还在学习。。。

我在HTML中有一个只有的表

<tr id="linha_1">
    <td><input type="text" name="nome_cor[]" value="" /></td>
    <td><input type="text" name="cod_cor[]" value="" /></td>
    <td><input type="file" name="img_cor[]" /></td>
    <td><input type="button" value="Remover" id="remove" onclick="$.removeLinha(this);" /></td>
</tr>

我还有一个JS脚本,它向这个表添加新行,这个脚本复制了第一行,这样用户就可以添加更多的颜色。。。

$(document).ready(function()
{
    var row_limit = 0;
    $('#add').click(function()
    {
        var linha_total = $('tbody#repetir tr').length;
        if (row_limit == 0 || row_limit > linha_total)
        {
            var linha = $('tbody#repetir tr').html();
            var linha_total = $('tbody#repetir tr').length;             
            var linha_id = $('tbody#repetir tr').attr('id');                
            $('tbody#repetir').append('<tr id="linha_' + (linha_total + 1) + '">' + linha + '</tr>');
        }
        else
        {
         alert("Desculpe, mas você só pode adicionar até " + limite_linhas + " linhas!");
         }                      
});

使用malsup表单插件通过post:发送数据

$("#send").click(function(event) {
    event.preventDefault();
    $("#form-tapete").ajaxForm({        
        // validation and progress bar (*not important to the question i think*)
    },
    url: 'dados-tapete.php',
    resetForm: false
 }).submit();

我正试图用以下代码在PHP中阅读这篇文章:

for ($i=0; $i < sizeof($cod_cor); $i++)
{
    $path_cor = "catalogo/tapete/cor/";
    $path_cor = $path_cor.basename($_FILES["img_cor"]["name"][$i]); 
    if (!move_uploaded_file($_FILES["img_cor"]["tmp_name"][$i], $path_cor)) 
        die("Ocorreu um erro ao enviar a imagem, tente novamente!"); 
    $cor_img_name = "catalogo/tapete/cor/".$_FILES["img_cor"]["name"][$i]; 
    $cadastra_cores = $con->sql_query("INSERT INTO tape_cores VALUES ('$nome_tapete','$cod_cor[$i]','$nome_cor[$i]','$path_cor')"); 
}

PHP脚本可以读取值并将其发送到数据库,但只有第一个值。。。动态添加的行不会出现在$_POST数组中。。。

我搜索了一下,在这里找到了一些问题,但没有解决方案。。。

很抱歉英语又不好了,如果你听不懂我的话,我可以试着用其他的话来解释。。。感谢

我会将JQuery与以下内容一起使用:

$.post( "test.php", $( "#testform" ).serialize() );

对于Malsup JQuery,请使用formSerialize();

var queryString = $('#myFormId').formSerialize();  
$.post('myscript.php', queryString);