Javascript 未定义索引错误消息

Javascript 未定义索引错误消息,javascript,php,sql,for-loop,mysqli,Javascript,Php,Sql,For Loop,Mysqli,我正在尝试将表单中的一些项插入到我的表中,该表名为products。表单如下所示: 正如您所看到的,我提到了一个链接,它是添加更多供应商:+,它只是在表单中添加了一个新行。其背后的脚本是: <script> $("#addbtn").click(function(){ var next = parseInt($('#counter').val()) + 1; $("#group"

我正在尝试将表单中的一些项插入到我的表中,该表名为
products
。表单如下所示:

正如您所看到的,我提到了一个链接,它是添加更多供应商:+,它只是在表单中添加了一个新行。其背后的脚本是:

<script>
        $("#addbtn").click(function(){
            var next = parseInt($('#counter').val()) + 1;
            $("#group").append("<table class='table table-hover'><tr><th style='padding-left:10px'>Name of supplier ("+next+")</th><th>Terms of sending</th><th>Guarantee</th><th>Price</th><th>Colors (use , for separation)</th></tr><tr><td style='padding-left:10px'><input name='supplier_name_("+next+")' type='text'></input></td><td><input name='supplier_sending_("+next+")' type='text'></input></td><td><input name='supplier_guarantee_("+next+")' type='text'></input></td><td><input name='supplier_price_("+next+")' type='text'></input></td><td><input name='supplier_colors_("+next+")' type='text'></input></td></tr></table>");
            $('#counter').val(next);
        });
        </script>
所有其他错误都与此类似(未定义索引&我在For循环中指定的每个输入名称的未定义变量)

如果你对此有任何想法,请告诉我,因为我真的很感激。谢谢:)

更新:

当我放置var_dump($_POST)时,我得到以下结果:

    ["supplier_name_1"]=>
  string(10) "supplier 1"
  ["supplier_sending_1"]=>
  string(7) "terms 1"
  ["supplier_guarantee_1"]=>
  string(11) "guarantee 1"
  ["supplier_price_1"]=>
  string(7) "price 1"
  ["supplier_colors_1"]=>
  string(8) "colors 1"
  ["supplier_name_2"]=>
  string(10) "supplier 2"
  ["supplier_sending_2"]=>
  string(7) "terms 2"
  ["supplier_guarantee_2"]=>
  string(11) "guarantee 2"
  ["supplier_price_2"]=>
  string(7) "price 2"
  ["supplier_colors_2"]=>
  string(8) "colors 2"
  ["supplier_name_3"]=>
  string(10) "supplier 3"
  ["supplier_sending_3"]=>
  string(7) "terms 3"
  ["supplier_guarantee_3"]=>
  string(11) "guarantee 3"
  ["supplier_price_3"]=>
  string(7) "price 3"
  ["supplier_colors_3"]=>
  string(8) "colors 3"
  ["counter"]=>
  string(1) "3"
我现在得到的错误是:

未定义变量:供应商名称_

未定义变量:供应商\发送_

未定义变量:供应商担保_

未定义变量:供应商价格_

未定义变量:供应商颜色_


html中有
供应商名称(“+next+”)
,但php中有
$\u POST['supplier\u name.'$p.']
。它与()不同<代码>变量转储($\u POST);在php中,检查html输入名称是否与错误行上的POST关键字名称匹配

更新:

看起来你在使用变量。 而不是

$supplier_name_ . $p = isset($_POST['supplier_name_'.$p.'']);
试一试


适用于“供应商名称”和其他有效的情况。

根据您更新的问题,我相信循环将持续到$p=3,但您已使用静态数字5作为条件

因为$p的值是空的,或者您可以说迭代4和5中不存在这些值,所以您会遇到这个问题


您应该获得确切的长度并使用它,而不是使用$py。您可以使用$supplier\u name\ux$p=isset($_POST['supplier_name.'$p.']);如果您在php中遇到未定义的错误,只需使用isset()更好地使用三元运算符,如果未定义,则使用值elseskip@Deep我试过了,但仍然得到了未定义的变量。该问题的另一个更新已提交。请检查一下。谢谢这意味着$p在循环中的迭代中没有值,也就是说,循环没有运行$p等于4和5。谢谢,伙计,我这样做了,我把结果作为问题的更新发布了。请看一看。谢谢我已经多次尝试在for循环中设置$p=3,但这个问题仍然存在。请先在我的答案中给出建议。可能你正在处理多个问题。考虑到更新中的错误,$p与此无关。
    ["supplier_name_1"]=>
  string(10) "supplier 1"
  ["supplier_sending_1"]=>
  string(7) "terms 1"
  ["supplier_guarantee_1"]=>
  string(11) "guarantee 1"
  ["supplier_price_1"]=>
  string(7) "price 1"
  ["supplier_colors_1"]=>
  string(8) "colors 1"
  ["supplier_name_2"]=>
  string(10) "supplier 2"
  ["supplier_sending_2"]=>
  string(7) "terms 2"
  ["supplier_guarantee_2"]=>
  string(11) "guarantee 2"
  ["supplier_price_2"]=>
  string(7) "price 2"
  ["supplier_colors_2"]=>
  string(8) "colors 2"
  ["supplier_name_3"]=>
  string(10) "supplier 3"
  ["supplier_sending_3"]=>
  string(7) "terms 3"
  ["supplier_guarantee_3"]=>
  string(11) "guarantee 3"
  ["supplier_price_3"]=>
  string(7) "price 3"
  ["supplier_colors_3"]=>
  string(8) "colors 3"
  ["counter"]=>
  string(1) "3"
$supplier_name_ . $p = isset($_POST['supplier_name_'.$p.'']);
${'supplier_name_' . $p} = isset($_POST['supplier_name_'.$p.'']);
${"supplier_name_$p"} = isset($_POST['supplier_name_'.$p.'']);