Hello Everybody,
My code is inserting only 1 line to DataBase
Im ofcourse passing an array from html - for example in my html input i set the name like that name=“rooms[]”
My php loop inserting only 1 result to database, but when im echo the variable, it shows that it already contain everything.
Coming from C# background, thinking that this is what making me so confused about php.
Thanks In Advance
<?php
require_once(“connection.php”);
$hotelName = $_POST[‘hotelname’];
$roomname = $_POST[‘roomname’];
$promoName = $_POST[‘promotionname’];
$price = $_POST[‘prices’];
$promotionQuery = “insert into promotions
(hotelname
, roomname
, promotionname
, price
) values (?,?,?,?)”;
$promotionStatement = $con->prepare($promotionQuery);
for ($i = 0; $i<count($roomname); $i++) {
echo $price[$i];
echo $roomname[$i];
$promotionStatement->bind_param(“sssi”, $hotelName, $roomname[$i], $promoName, $price[$i]);
$promotionStatement->execute();
}
$promotionStatement->close();
?>