「連絡先の追加」セクションのあるフォームがあります。クリックすると、フォームに別の行が追加され、さらに 3 つの入力ボックスが追加されます。(jfiddle のコードの一部: http://jsfiddle.net/fmdx/cYxYP/ )
HTML
<form method="post" action="">
<div style="padding-left:40px;">
<div id="customcopies" style="padding-left:40px;">
1. Name: <input type="text" id="copiestoname_1" name="copiestoname[]" placeholder="Jane Doe Smith" required>, Institution: <input type="text" id="copiestoinst_1" name="copiestoinst[]" placeholder="Bank" required>, Method: <input type="text" id="copiestomethod_1" name="copiestomethod[]" placeholder="Email" required>
</div>
</div>
<input type="submit" name="submit_val" value="Submit" />
</form>
これは挿入用の PHP/MYSQL です。
if (isset($_POST['submit_val'])) {
foreach ($_POST['copiestoname'] as $key=>$value) {
$copiestoname = mysql_real_escape_string($value);
mysql_query("INSERT INTO copiesto (name) VALUES ('$copiestoname')") or die(mysql_error());
echo "Completed";
}
echo "" . count($_POST['copiestoname']) . " Names Added<br>";
mysql_close();
}
データベース内のテーブルは次のとおりです。
Table Name: copiesto
+-------------+-------------+-------------+---------+
| index | name | institution | method |
+-------------+-------------+-------------+---------+
現在のMYSQLコードを拡張して、他の2つの配列からエントリを受け入れ、そのループ中に同じMYSQL行にデータを入力するにはどうすればよいですか?