
if (isset($_POST['items'])) {
$items = $_POST['items'];
foreach ($items['service'] as $key => $item) {
$optionprice = ORM::factory('Optionprice');
$dataOptions = array(
'category_id' => $cat->pk(),
'item_id' => $key,
'service' => $item,
'unit' => $items['unit'][$key],
'price' => $items['price'][$key]
);
$optionprice->values($dataOptions);
$optionprice->save();
}
}
<form action="task.php" method="post">
<input type="text" name="service" required>
<input type="text" name="unit" required>
<input type="number" name="price" required>
<input type="submit" name="submit" value="ok">
</form>if (isset($_POST['submit'])) {
if ($_POST['service'] != '' && $_POST['unit'] != '' && $_POST['price'] != '') {
$sql = "INSERT INTO `test` (`service`, `unit`, `price`) VALUES (:service, :unit, :price)";
$statement = $pdo->prepare($sql);
$statement->execute([
'service' => $_POST['service'],
'unit' => $_POST['unit'],
'price' => $_POST['price']
]);
} else {
die('isset empty data.');
}
}
if (isset($_POST['items'])) {
$items = $_POST['items'];
foreach ($items['service'] as $key => $item) {
$optionprice = ORM::factory('Optionprice');
$dataOptions = array(
'category_id' => $cat->pk(),
'item_id' => $key,
'service' => $item,
'unit' => $items['unit'][$key],
'price' => $items['price'][$key]
);
$optionprice->values($dataOptions);
$optionprice->save();
}
}