[Help Needed] - Php not inserting into SQL -> bug or Im doing something wrong?

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();

?>

on your development machine you should set PDO to show errors

$pdo = new PDO('mysql:host=localhost;dbname=someTable', 'username', 'password', [
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);

or MySQLi

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

I tried this and Im not getting any error.

Is php’s error_reporting set to E_ALL and display_errors set to ON, preferably in the php.ini on your system, so that php will report and display all the errors it detects, which will now include database statement errors?

Sponsor our Newsletter | Privacy Policy | Terms of Service