Free PHP Booking Slots Calendar

May 25th, 2014

This is the second and latest version of my PHP Booking Slots Calendar.
I got so many emails requesting new features and this version contains the following:

  • Set the starting and ending slot times
  • Set as many slots her hour as you need
  • Set the cost per slot
  • Recognises part booked, fully booked, and past dates
  • Set a closed day(s) when no bookings can be made
  • Set alternative currencies
  • Leap year safe

After a booking is made, a user ends up at the book_slots.php page.
This is the page which actually books the slots. I left this page deliberately sparse so that you can integrate it with your own basket or redirect the user to a payment gateway.
Check out the live demo here.

Compatability

The PHP Booking Slots Calendar works with IE7+, Ipad, Chrome and Firefox.
Older browsers may struggle to correctly display the “Make Booking” button because it uses CSS3.

PHP Free Booking Slots Calendar

Features

When a checkbox is clicked, the basket section shows the current total cost and selected slots. The cost and slots are recalculated every time a slot is clicked.

Selected Slots

Setting up the calendar

All you need is a MySQL database and connection details, and the ability to upload files to your server.
I have included calendar_table_schema.sql file which you can use to import directly into phpMyAdmin. Your “bookings” table should look like this:

MySQL bookings schema

Free to use, let me know how you get on, Iā€™d like to hear from you.

Download PHP Booking Slots Calendar

Click here to download PHP Booking Slots Calendar

  • Tan Le Nguyen

    Hello, thanks for this free application. It works very well. Might I ask if there is a way to limit bookings to a week or a month? I want to use this for an event that lasts only for a month.

    • Planetphp

      Hi Tan

      Thanks for the email.

      An easy way to limit bookings to a month would be to remove the back and forward arrow
      links from the calendar to stop users from navigating. Changing Line 214 and 216 of class_calendar.php from « and » to   would remove the navigation arrows and show a space instead.

      As for showing just a week. Not sure that would be possible because the calendar works on a monthly basis.

      Best wishes

      Mark

      • Tan Le Nguyen

        Thanks again Mark!
        Sorry for the late response.

        I thought of removing the two arrows too!
        But if the event runs from July 15 to August 15 2014, would that be difficult to disable August 16 17 18 and so on?

        • admin

          Hi Tan

          You could tweak the make_days_array method of class_calendar.php.
          On line 110 there is a for loop to create the days array:

          for ($i = 1; $i < = $num_days_month; $i++)

          Say you wanted the calendar to show only 15th - 20th, you could change it:

          for ($i = 15; $i < = 20; $i++)

          That is probably all you can do to limit the days shown because calendars naturally run on a monthly basis. Hope it helps!

        • Planetphp

          Hi Tan

          You could tweak the make_days_array method of class_calendar.php.
          On line 110 there is a for loop to create the days array:

          for ($i = 1; $i <= $num_days_month; $i++)

          Say you wanted the calendar to show only 15th ā€“ 20th, you could change it:

          for ($i = 15; $i <= 20; $i++)

          That is probably all you can do to limit the days shown because calendars naturally run on a monthly basis. Hope it helps!

          • Tan Le Nguyen

            That works perfectly!

            I really appreciate your help, Mark.

            Tan

          • Sowmya RK

            Hi Sir,

            Am looking for an option where there will be table of a person with his availability timings. based on that the slot has to come. How can I do.

            Its working fine. am very happy. If you facilitate this it will be a great help

  • Robbaust

    Hi I’m testing your script and once you click book and it goes to the booking confirmation page it displays the following

    Array
    (
    [slots_booked] => 07:00:00|08:00:00|
    [booking_date] => 2014-07-11
    [cost_per_slot] => 20.50
    [name] => Robert
    [email] => robert@test.com
    [phone] => 992939
    )

    how would I get rid of the array and the two brackets part and keep the rest

    Thanks in advance
    Rob

    • Planetphp

      You could either comment out or remove this code from book_slots.php:

      print_r(”);
      print_r($booking_array);
      print_r(”);

      • Robbaust

        hi thanks that worked great

        how would i get the times booked email to me and say the person that booked the time slots if that is possible sorry for the questions i’m slowly learning

        thanks again
        Rob

    • Planetphp

      Sending an email in PHP using the mail() function is simple:

      $message = “Hello RobA booking has been made on ” . $booking_date . ” and the slots booked are ” . $slots_booked;

      mail(“email”, “Subject”, $message);

  • yasin

    hi there,
    Is it possible to choose only one hour
    Can we restrict to that multiple choice

  • yasin

    I show days in the months of Turkish formats

  • confused

    i have an excellent use case for this tool and it looks amazing. I’m still a bit new to php. If I download this zip and then extract it to my MAMP Root folder, should I then be able to simply load the calendar.php fil on my local host and then see the calendar as per the demo? Right now, I’m seeing a blank page. Do I need to do something more? Thanks

  • Ziggy

    Hi. Tried uploading your calendar code and I’m getting a blank page as well. I’m a bit self taught in the world of php etc, what software version requirements do you need to be using for it to work. My code still uses mysql syntax as oppose to mysqli. Can you help, please?

    • Planetphp

      The code makes use of the Mysqli extension so you would need to enable this in your php.ini file. Should take 5 minutes to edit and restart.

      Using the old Mysql extension is not recommended any more. The main useful features are:
      - an Object-oriented interface
      - support for prepared statements
      - support for multiple statements
      - support for transactions
      - enhanced debugging capabilities
      - embedded server support.

  • Arminas

    Hello, i want to ask how to do saturday not available like sunday, i’ve trying everything but don’t have any mind..

    • Planetphp

      Simple. Just edit line #27 of class_calendar.php so it reads:

      public $day_closed = array(“Saturday”, “Sunday”);

      I changed the online demo so you can see the change in action. Was this what you wanted?

  • DIK ya

    Hello,sorry i’m new in php..i want to ask why went i run this coding i get notice:undefined variable??

    • Planetphp

      Hi. Thanks for getting in touch. Which variable is undefined? Does the error give a variable name or a line number?

  • David

    I’m also just seeing a blank page, can you give us ideas on versions required for php etc? Thanks, David

    • Planetphp

      Hi David.

      A blank page, that is strange. I am running PHP version 5.5 but I developed it with 4.8 and there are no special requirements other than having the Mysqli extension installed. I would be surprised if you don’t have it installed though. You can run phpinfo(); to check this.

      Add this line to the calendar.php file, just under the opening <?php on line #1:

      error_reporting(E_ALL);
      ini_set('display_errors', 1);

      It will show any code errors in case error reporting is turned off. Do you get any messages?

  • David

    Just added your code and get the following error message;

    Fatal error: Call to undefined function cal_days_in_month() in /sandbox/dhamill/slots/classes/class_calendar.php on line 106

  • david

    Line 106 is as follows

    // Calculate the number of days in the selected month

    $num_days_month=cal_days_in_month(CAL_GREGORIAN, $month, $year);

    • Planetphp

      Hi David

      cal_days_in_month is a built in PHP function since version 4 if I remember rightly.
      As I write this, the latest stable version is 5.5 and version 4 was release back in 2001!
      What version of PHP are you running?

  • dave

    Hi I got thi error
    Notice: Undefined variable: day_count in C:wampwwwcontrolpanelMajor Projectclassesclass_calendar.php on line 162 and 165 16 162

    ddp

    • dave

      sry i meant this error

      Notice: Undefined variable: day_count in C:wampwwwcontrolpanelMajor Projectclassesclass_calendar.php on line 162 and 165

      any idea what is wrong? I checked the line and this is what it is

      if ($day_count >= $this->booking_slots_per_day && $tag == ”)

      $tag = 3;

      if ($day_count >0 && $tag == ”)

      $tag = 1;

      • Planetphp

        Hi Dave

        I checked and tere is no variable $day_count in class_calendar. But there was on the older version… I think you might have downloaded this instead. Can you try again and download the zip file on this page?

        • dave

          Thank you so much! It worked like a charm :) Much appreciated Planetphp

  • luke

    Hi,

    Great booking system, i was wondering how i would change the amount of slots for each day so that it isn’t in minutes. An example being having 30 slots a day that all say start time “17:00″ and end time that says “18:00″.

    Thanks!

    • Planetphp

      Currently it is not possible to set a limit of slots per time but it could be possible. I’m going to add this to my action list and it will get added to the next version. It’s a really good idea…

  • Ian Haney

    Hi, I like the look of this but can it do the following or can it be customised to do the following

    PayPal integration
    Multiple bookings so users can book slots on one day and then book a slot on another day and pay the total due via PayPal
    Can it handle discounts

    Thank you in advance

    Ian

    • Planetphp

      Hi Ian

      PayPal integration is something I deliberately left off because it is complicated and the API frequently changes. If I added this I would end up supporting this and I just don’t have the time. I left the payment part open for any developer to integrate whatever payment solution they use.

      I like your idea of multiple bookings on different days and I have added this to my action list for the next version.

      As for discounts, that really comes down to the developer to inetgrate whatever discount solution they require. The costs are passed to the ‘book_slots.php’ page so it is easy to change the prices.

      Thanks!

      Mark

  • Andre

    Hi there!! ;) Thanks very much for your code!! It’s work fine.

    I need the similar code but without the Price and I need to know how can I configure the time for I need the similar code but without the Price and I need to know how can I configure the time for show different hours from your code.

    Can you help me?
    Thanks you a lot!!! ;)

    • Andre

      Hi again.

      Just to inform you that I managed to change what I asked earlier.

      Thanks anyway .

      :)

  • betty2002

    hello, first of all thanks for your job and sorry for my english. I need an anual book calendar that begin in the actual month, only used by one person (admin), and only change the color of the cell when is booked, anything else, no hours, can you help me?