I am stuck while inserting data to my mysql table using a foreach loop to insert multiple rows at a time.
foreach($event as $booking){
$startDate = $booking[DTSTART];
$checkIn = strtotime($startDate[value]);
$check_in = date("Y-m-d", $checkIn);
$endDate = $booking[DTEND];
$checkOut = strtotime($endDate[value]);
$check_out = date("Y-m-d", $checkOut);
$booking_source = "Airbnb";
$source_id = "2";
$summary = $booking[SUMMARY];
$description = $booking[DESCRIPTION];
$uid = $booking[UID];
$sql = "INSERT INTO test_ics (uid, check_in, check_out, summary, description, source, source_id) VALUES (?,?,?,?,?,?,?)";
$result = $conn->prepare($sql);
$result->bind_param('sssssss', $uid, $check_in, $check_out, $summary, $description, $booking_source, $source_id);
$result->execute();
echo "<br>";
echo "$check_in";
}
The code is working fine and inserting all the rows when I remove description and summary fields from the table where both of them are VARCHAR(2550) but when I am trying to run the code to insert rows with description and summary (like it is in the code above) its inserting only 10 rows.
Thanks
Notice: Use of undefined constant DTSTART - assumed 'DTSTART' in /home/fadipro/public_html/admin/get-airbnb-bookings.php on line 40
Notice: Use of undefined constant value - assumed 'value' in /home/fadipro/public_html/admin/get-airbnb-bookings.php on line 41
Notice: Use of undefined constant DTEND - assumed 'DTEND' in /home/fadipro/public_html/admin/get-airbnb-bookings.php on line 45
Notice: Use of undefined constant value - assumed 'value' in /home/fadipro/public_html/admin/get-airbnb-bookings.php on line 46
Notice: Use of undefined constant SUMMARY - assumed 'SUMMARY' in /home/fadipro/public_html/admin/get-airbnb-bookings.php on line 54
Notice: Use of undefined constant DESCRIPTION - assumed 'DESCRIPTION' in /home/fadipro/public_html/admin/get-airbnb-bookings.php on line 56
Notice: Use of undefined constant UID - assumed 'UID' in /home/fadipro/public_html/admin/get-airbnb-bookings.php on line 58
$event. How many records are you expecting to be inserted?VARCHAR(2550):/ just useTEXTvar_dump($event);to check the values. Maybe the summary/desc is bigger than you table field?$result = $conn->prepare($sql); $result->bind_param('sssssss', $uid, $check_in, $check_out, $summary, $description, $booking_source, $source_id); $result->execute();...any one of these three statements could fail and returnfalse(or throw an exception, depending on your config) but you don't seem to be testing any of them (and then checking the value of$conn->error), either that or you're suppressing exceptions somewhere