I want to insert multiple rows with the single query using PDO prepared statement but I don't want to insert any blank row.
Actually, I have four row in my form you can see in HTML below and when I fill only one row it insert three blank row also but I don't to insert any blank row
<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>
my code is like this
$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();
}
help me please...