I get values in array for one parameter which is width.
HTML file
<div class="col-sm-2"><input type="number" name="width[]" class="form-control"></div>
<div class="col-sm-2"><input type="number" name="width[]" class="form-control"></div>
<div class="col-sm-2"><input type="number" name="width[]" class="form-control"></div>
After I submit values I get only one record in db for width, other variables are all the same except for width which is different.
this is php code
if (isset($_POST['submit'])) {
$width = $_POST['width'];
$quantity = $_POST['quantity'];
$length = $_POST['length'];
$productID = $_POST['productID'];
$date = date("Y-m-d H:i");
foreach ($width as $value) {
$stmt=$conn->prepare("INSERT INTO testDB (width, quantity, length, productID)
VALUES (:witdh, :quantity, :length, :productID) ");
$stmt->bindParam(':witdh',$value);
$stmt->bindParam(':quantity',$quantity);
$stmt->bindParam(':length',$length);
$stmt->bindParam(':productID',$productID);
if($stmt->execute()){
echo "success";
exit();
}
else{
print_r($stmt->errorInfo());
}
}
}
$quantity, as this doesn't change in the loop, it will always be the same for each record. The only value which is different is the width field.