How to insert into MYSQL row from multiple $_POST arrays

前端 未结 1 603
情歌与酒
情歌与酒 2021-01-23 07:05

I have a form with an \"add contact\" section, where upon a click, it adds another row to the form with 3 more input boxes. (The segment of code on jfiddle: http://jsfiddle.net/

1条回答
  •  广开言路
    2021-01-23 07:32

    you can use for loop instead

    for ($i=0; $i < count($_POST['copiestoname']); $i++ ) {
      $copiestoname = mysql_real_escape_string($_POST['copiestoname'][$i]);
      $copiestoinst = mysql_real_escape_string($_POST['copiestoinst'][$i]);
      $copiestomethod = mysql_real_escape_string($_POST['copiestomethod'][$i]);
    
      mysql_query("INSERT INTO copiesto (name, institution, method) VALUES ('$copiestoname', '$copiestoinst', '$copiestomethod')") or die(mysql_error());
      echo "Completed";
    }
    

    0 讨论(0)
提交回复
热议问题