Hi,
i have problem in insert the booking details.Basically i am creating a room booking system. This is how my idea go, i fill in all the booking details, if there are available it will allow to book, else it not allow to continue. This is to prevent any duplicate booking details.
I create few tables which is ‘bookingdetail’,‘timeslot’,‘user’, ‘refroom’,‘rootype’
table bookingdetail
bookingID,
UserID,
RoomTypeID,
RefroomID,
TimeID,
BookingStatus,
Event,
StartDate,
EndDate`
table timeslot
TimeSlotID,TimeSlot
1 8.00-9.00am
2 9.00-10.00am
3 10.00-11.00am
4 11.00-12.00pm
table user
UserID,Username
1 ALEX
table refroom
RefroomID,Room,RoomID
1 TR1 1
2 TR2 1
3 MRU1 2
4 MRU2 2
table roomtype
RoomID,Room
1 Tutorial Room
2 Meeting Room
These are the table i create to run the room booking system.
public function actionProcessBooking() {
$modelBooking = new Bookingdetail();
//$Booking = get_class($modelBooking);
$this->performAjaxValidation($modelBooking);
$bookingStatus = Yii::app()->db->createCommand()
->select('BookingID,RefroomID,BookingStatus,TimeID,StartDate,EndDate')
->from('bookingdetail')
->where('BookingStatus=:BookingStatus',array(':BookingStatus'=> "1" ))
->queryAll();
if ( $bookingStatus) {
echo "The time slot of the room have been booked!"
. "Please reserve another room and time slot.Thank You.";
} else {
$command = Yii::app()->db->createCommand();
$command->insert('bookingdetail', array(
'UserID' => Yii::app()->session['ID'],
'RoomTypeID' => $_POST['roomtype'],
'RefroomID' => $_POST['referroomtype'],
'BookingStatus' => '1',
'Event' => $_POST['Bookingdetail']['Event'],
'TimeID' => $_POST['timeslot'],
'StartDate' => $_POST['Bookingdetail']['StartDate'],
'EndDate' => $_POST['Bookingdetail']['EndDate']
));
$this->redirect(Yii::app()->request->hostInfo . Yii::app()->request->baseURL . "/index.php/site/adminuserbookingdetails");
}
}
my idea is if the room is booked, the booking status is 1. So, i select from booking details which status is 1 will able to avoid user to book the same time,same room but somehow,the code above is not working. I hope got anyone able to guide me and correct me. I sorry if i not so good in php and database.