PDOプリペアドステートメントを使用して単一のクエリで複数の行を挿入したいが空白行を挿入しない。プリペインドステートメントを使用して空白行を挿入せずにMySQLに複数の行を挿入する方法
実は、私はあなたが以下のHTMLで見ることができる私の形の4つの行を持っていると私は一列のみを記入する際には、3空白行も挿入が、私は、任意の空白行
<form method="post">
<table>
<tr>
<td><input type="text" name="col1"></td>
<td><input type="text" name="col2"></td>
</tr>
<tr>
<td><input type="text" name="col1"></td>
<td><input type="text" name="col2"></td>
</tr>
<tr>
<td><input type="text" name="col1"></td>
<td><input type="text" name="col2"></td>
</tr>
<tr>
<td><input type="text" name="col1"></td>
<td><input type="text" name="col2"></td>
</tr>
</table>
</form>
を挿入するようにしていない私あなたのcol1とcol2には、あなたは、配列を使用する必要があり、複数あるように、コードがこの
$stmt = $pdo->prepare('INSERT INTO foo VALUES(:col1, :col2)');
foreach($data as $item)
{
$stmt->bindValue(':col1', $item[0]);
$stmt->bindValue(':col2', $item[1]);
$stmt->execute();
}
のようなものであることは...
? – Bhavin
「空」でチェックしてください。 –
@Bhavin私のコード –