I needed to insert some data to mysql database which is stored in a multi-dimensional array.
I have separate values and ready to put the data to database. It caused the problem that it reported that the part of statement "chccheung.BookingDate(Room,Date,From,To)" is not a correct format/syntax, also it has error nearby "From,To)".
After testing and debugging, I could not find out any solution to solve this problem, can anyone help me, thanks in advance.
open the database connection
.......
foreach($Booking as $key => $value){
$rmID = $key;
foreach($value as $format => $array){
foreach($array as $date => $detail){
$bookDate = $date;
foreach($detail as $period =>$fromTo){
if($period=="user"){
$user = $fromTo;//$query = "INSERT INTO RmBooking_Applicant(user) VALUES ($fromTo)";
}
if($period=="username"){
$userID = $fromTo;//$query = "INSERT INTO RmBooking_Applicant(username) VALUES ($fromTo)";
}
if($period=="from"){
$fromTime = $fromTo;//$query = "INSERT INTO BookingDate(From) VALUES ($fromTo)";
}
if($period=="to"){
$toTime = $fromTo;//$query = "INSERT INTO BookingDate(To) VALUES ($fromTo)";
}
}
}
}
}
$bookingInformation = "INSERT INTO testingData.BookingDate(Room,Date,From,To) VALUES($rmID,$date,";
$bookingInformation .= implode(',', $fromTo);
$bookingInformation .= ")";
$applicantDetails = "INSERT INTO testingData.RmBooking_Applicant(username,user) VALUES(";
$applicantDetails .= implode(',', $userID);
$applicantDetails .= implode(',', $user);;
$applicantDetails .= ")";
......
close database connection