{"id":132369,"date":"2023-03-10T08:18:05","date_gmt":"2023-03-10T08:18:05","guid":{"rendered":"https:\/\/phppot.com\/?p=20461"},"modified":"2023-03-10T08:18:05","modified_gmt":"2023-03-10T08:18:05","slug":"event-management-system-project-in-php","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2023\/03\/10\/event-management-system-project-in-php\/","title":{"rendered":"Event Management System Project in PHP"},"content":{"rendered":"<div class=\"modified-on\" readability=\"7.0909090909091\"> by <a href=\"https:\/\/phppot.com\/about\/\">Vincy<\/a>. Last modified on March 10th, 2023.<\/div>\n<p>When managing events, the date and time come into the picture. So, the calendar component is the best to render events in a viewport. It is convenient compared to other views like card-view or list-view.<\/p>\n<p>This example uses the JavaScript library <strong>FullCalendar<\/strong> to render and manage events. The events are from the database by using PHP and MySQL.<\/p>\n<p>The following script gives you a simple event management system in PHP with AJAX. The AJAX handlers connect the PHP endpoint to manage events with the database.<\/p>\n<p>In a previous tutorial, we have seen how to create a <a href=\"https:\/\/phppot.com\/php\/create-ajax-based-event-management-system-with-bootstrap\/\">PHP event management system with Bootstrap<\/a>.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-large wp-image-20546\" src=\"https:\/\/phppot.com\/wp-content\/uploads\/2023\/03\/create-edit-delete-events-in-php-550x417.jpg\" alt=\"create edit delete events in php\" width=\"550\" height=\"417\" srcset=\"https:\/\/phppot.com\/wp-content\/uploads\/2023\/03\/create-edit-delete-events-in-php-550x417.jpg 550w, https:\/\/phppot.com\/wp-content\/uploads\/2023\/03\/create-edit-delete-events-in-php-300x227.jpg 300w, https:\/\/phppot.com\/wp-content\/uploads\/2023\/03\/create-edit-delete-events-in-php-768x582.jpg 768w, https:\/\/phppot.com\/wp-content\/uploads\/2023\/03\/create-edit-delete-events-in-php.jpg 1200w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\"><\/p>\n<h2>Step 1: Create an HTML base with the FullCalendar library<\/h2>\n<p>The client-side script has the HTML with the required dependencies. This HTML uses CDN to import the JS and CSS. It uses the following libraries<\/p>\n<ol>\n<li>FullCalendar.<\/li>\n<li>MomentJS.<\/li>\n<li>jQuery and jQuery UI.<\/li>\n<\/ol>\n<p>It has an empty DIV target that will display the calendar UI after initiating the FullCalendar JavaScript library class.<\/p>\n<p class=\"code-heading\">index.php<\/p>\n<pre class=\"prettyprint\"><code class=\"language-html\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;Event management in php&lt;\/title&gt; &lt;script type=\"text\/javascript\" src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/moment.js\/2.22.2\/moment.js\"&gt;&lt;\/script&gt;\n&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/jquery\/3.3.1\/jquery.min.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\n&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/jqueryui\/1.12.1\/jquery-ui.min.js\"&gt;&lt;\/script&gt;\n&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/fullcalendar\/3.9.0\/fullcalendar.min.js\"&gt;&lt;\/script&gt;\n&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/fullcalendar\/3.9.0\/locale-all.js\"&gt;&lt;\/script&gt;\n&lt;link href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/fullcalendar\/3.9.0\/fullcalendar.min.css\" rel=\"stylesheet\"&gt;\n&lt;link rel=\"stylesheet\" href=\"\/\/code.jquery.com\/ui\/1.13.2\/themes\/base\/jquery-ui.css\"&gt;\n&lt;link rel=\"stylesheet\" href=\"assets\/css\/style.css\"&gt;\n&lt;link rel=\"stylesheet\" href=\"assets\/css\/form.css\"&gt;\n&lt;script src=\"assets\/js\/event.js\"&gt;&lt;\/script&gt;\n&lt;style&gt;\n.btn-event-delete { font-size: 0.85em; margin: 0px 10px 0px 5px; font-weight: bold; color: #959595;\n}\n&lt;\/style&gt;\n&lt;\/head&gt; &lt;body&gt; &lt;div class=\"phppot-container\"&gt; &lt;h2&gt;Event management in php&lt;\/h2&gt; &lt;div class=\"response\"&gt;&lt;\/div&gt; &lt;div class=\"row\"&gt; &lt;input type=\"text\" name=\"filter\" id=\"filter\" placeholder=\"Choose date\" \/&gt; &lt;button type=\"button\" id=\"button-filter\" onClick=\"filterEvent();\"&gt;Filter&lt;\/button&gt; &lt;\/div&gt; &lt;div class=\"row\"&gt; &lt;div id='calendar'&gt;&lt;\/div&gt; &lt;\/div&gt; &lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n<h2>Step 2: Create MySQL Structure in phpMyAdmin<\/h2>\n<p>This example creates a persistent event management system in PHP. The newly created or modified event data are permanently stored in the database.<\/p>\n<p>This script has the CREATE STATEMENT and indexes of the&nbsp;tbl_events database. Do the following steps to set up this database in a development environment.<\/p>\n<ol>\n<li>Create a database and import the below SQL script into it.<\/li>\n<li>Configure the newly created database in config\/db.php of this project.<\/li>\n<\/ol>\n<h3>Database script<\/h3>\n<p class=\"code-heading\">sql\/structure.sql<\/p>\n<pre class=\"prettyprint\"><code class=\"language-sql\">--\n-- Database: `full_calendar`\n-- -- -------------------------------------------------------- --\n-- Table structure for table `tbl_events`\n-- CREATE TABLE `tbl_events` ( `id` int(11) NOT NULL, `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, `start` date DEFAULT NULL, `end` date DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=latin1; --\n-- Indexes for dumped tables\n-- --\n-- Indexes for table `tbl_events`\n--\nALTER TABLE `tbl_events` ADD PRIMARY KEY (`id`); --\n-- AUTO_INCREMENT for dumped tables\n-- --\n-- AUTO_INCREMENT for table `tbl_events`\n--\nALTER TABLE `tbl_events` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;\n<\/code><\/pre>\n<h3>Database configuration<\/h3>\n<p class=\"code-heading\">db.php<\/p>\n<pre class=\"prettyprint\"><code class=\"language-php\">&lt;?php\n$conn = mysqli_connect(\"localhost\", \"root\", \"\", \"full_calendar\"); if (! $conn) { echo \"Failed to connect to MySQL: \" . mysqli_connect_error();\n}\n?&gt;\n<\/code><\/pre>\n<h2>Step 3: Initiate Fullcalendar and create listeners to manage events<\/h2>\n<p>This section initiates the JavaScript calendar library with suitable settings. For example, the below script enables the following directives to allow mouse events to make changes in the calendar.<\/p>\n<ol>\n<li>editable \u2013 It will enable event editing on the calendar by switching it on.<\/li>\n<li>droppable \u2013 It supports event <a href=\"https:\/\/phppot.com\/jquery\/jquery-drag-and-drop\/\">drag and drops<\/a> to change the date.<\/li>\n<li>eventResize \u2013 It supports inline extending or reducing the event period by resizing.<\/li>\n<li>eventLimit \u2013 It allows limiting the number of events displayed on a date instance.<\/li>\n<li>displayEventTime \u2013 It shows event time if added.<\/li>\n<\/ol>\n<p>The Fullcalendar property \u201cevents\u201d specifies the array of events rendered download. In this example, it has the PHP endpoint URL to read calendar events dynamically from the database.<\/p>\n<p>This script maps the calendar event\u2019s select, drag, drop, and resize with the defined <a href=\"https:\/\/phppot.com\/php\/ajax-programming-with-php\/\">AJAX handlers<\/a>.<\/p>\n<pre class=\"prettyprint\"><code class=\"language-javascript\">$(document).ready(function() { var calendar = $('#calendar').fullCalendar({ editable: true, eventLimit: true, droppable: true, eventColor: \"#fee9be\", eventTextColor: \"#232323\", eventBorderColor: \"#CCC\", eventResize: true, header: { right: 'prev, next today', left: 'title', center: 'listMonth, month, basicWeek, basicDay' }, events: \"ajax-endpoint\/fetch-calendar.php\", displayEventTime: false, eventRender: function(event, element) { element.find(\".fc-content\").prepend(\"&lt;span class='btn-event-delete'&gt;X&lt;\/span&gt;\"); element.find(\"span.btn-event-delete\").on(\"click\", function() { if (confirm(\"Are you sure want to delete the event?\")) { deleteEvent(event); } }); }, selectable: true, selectHelper: true, select: function(start, end, allDay) { var title = prompt('Event Title:'); if (title) { var start = $.fullCalendar.formatDate(start, \"Y-MM-DD HH:mm:ss\"); var end = $.fullCalendar.formatDate(end, \"Y-MM-DD HH:mm:ss\"); addEvent(title, start, end); calendar.fullCalendar('renderEvent', { title: title, start: start, end: end, allDay: allDay }, true ); } calendar.fullCalendar('unselect'); }, eventClick: function(event) { var title = prompt('Event edit Title:', event.title); if (title) { var start = $.fullCalendar.formatDate(event.start, \"Y-MM-DD HH:mm:ss\"); var end = $.fullCalendar.formatDate(event.end, \"Y-MM-DD HH:mm:ss\"); editEvent(title, start, end, event); } }, eventDrop: function(event) { var title = event.title; if (title) { var start = $.fullCalendar.formatDate(event.start, \"Y-MM-DD HH:mm:ss\"); var end = $.fullCalendar.formatDate(event.end, \"Y-MM-DD HH:mm:ss\"); editEvent(title, start, end, event); } }, eventResize: function(event) { var title = event.title; if (title) { var start = $.fullCalendar.formatDate(event.start, \"Y-MM-DD HH:mm:ss\"); var end = $.fullCalendar.formatDate(event.end, \"Y-MM-DD HH:mm:ss\"); editEvent(title, start, end, event); } } }); $(\"#filter\").datepicker();\n});\nfunction addEvent(title, start, end) { $.ajax({ url: 'ajax-endpoint\/add-calendar.php', data: 'title=' + title + '&amp;start=' + start + '&amp;end=' + end, type: \"POST\", success: function(data) { displayMessage(\"Added Successfully\"); } });\n} function editEvent(title, start, end, event) { $.ajax({ url: 'ajax-endpoint\/edit-calendar.php', data: 'title=' + title + '&amp;start=' + start + '&amp;end=' + end + '&amp;id=' + event.id, type: \"POST\", success: function() { displayMessage(\"Updated Successfully\"); } });\n} function deleteEvent(event) { $('#calendar').fullCalendar('removeEvents', event._id); $.ajax({ type: \"POST\", url: \"ajax-endpoint\/delete-calendar.php\", data: \"&amp;id=\" + event.id, success: function(response) { if (parseInt(response) &gt; 0) { $('#calendar').fullCalendar('removeEvents', event.id); displayMessage(\"Deleted Successfully\"); } } });\n}\nfunction displayMessage(message) { $(\".response\").html(\"&lt;div class='success'&gt;\" + message + \"&lt;\/div&gt;\"); setInterval(function() { $(\".success\").fadeOut(); }, 5000);\n} function filterEvent() { var filterVal = $(\"#filter\").val(); if (filterVal) { $('#calendar').fullCalendar('gotoDate', filterVal); $(\"#filter\").val(\"\"); }\n}\n<\/code><\/pre>\n<h2>Step 4: Create AJAX endpoints to create, render and manage event data<\/h2>\n<p>This section shows the PHP code for the AJAX endpoint. The Fullcalendar callback handlers call these endpoints via AJAX.<\/p>\n<p>This endpoint receives the event title, start date, and end date. It processes the requested database operation using the received parameters.<\/p>\n<p class>ajax-endpoint\/fetch-calendar.php<\/p>\n<pre class=\"prettyprint\"><code class=\"language-php\">&lt;?php\nrequire_once \"..\/config\/db.php\"; $json = array();\n$sql = \"SELECT * FROM tbl_events ORDER BY id\"; $statement = $conn-&gt;prepare($sql);\n$statement-&gt;execute();\n$dbResult = $statement-&gt;get_result(); $eventArray = array();\nwhile ($row = mysqli_fetch_assoc($dbResult)) { array_push($eventArray, $row);\n}\nmysqli_free_result($dbResult); mysqli_close($conn);\necho json_encode($eventArray);\n?&gt;\n<\/code><\/pre>\n<p class>ajax-endpoint\/add-calendar.php<\/p>\n<pre class=\"prettyprint\"><code class=\"language-php\">&lt;?php\nrequire_once \"..\/config\/db.php\"; $title = $_POST['title'];\n$start = $_POST['start'];\n$end = $_POST['end'];\n$statement = $conn-&gt;prepare('INSERT INTO tbl_events (title,start,end) VALUES (?,?,?)');\n$statement-&gt;bind_param('sss', $title, $start, $end);\n$rowResult = $statement-&gt;execute();\nif (! $rowResult) { $result = mysqli_error($conn);\n}\n?&gt;\n<\/code><\/pre>\n<p class>ajax-endpoint\/edit-calendar.php<\/p>\n<pre class=\"prettyprint\"><code class=\"language-php\">&lt;?php\nrequire_once \"..\/config\/db.php\"; $id = $_POST['id'];\n$title = $_POST['title'];\n$start = $_POST['start'];\n$end = $_POST['end'];\n$statement = $conn-&gt;prepare('UPDATE tbl_events SET title = ?, start= ?, end=? WHERE id = ?');\n$statement-&gt;bind_param('sssi', $title, $start, $end, $id);\n$rowResult = $statement-&gt;execute();\nmysqli_close($conn);\n?&gt;\n<\/code><\/pre>\n<p class>ajax-endpoint\/delete-calendar.php<\/p>\n<pre class=\"prettyprint\"><code class=\"language-php\">&lt;?php\nrequire_once \"..\/config\/db.php\"; $id = $_POST['id'];\n$statement = $conn-&gt;prepare('DELETE from tbl_events WHERE id= ?');\n$statement-&gt;bind_param('i', $id);\n$rowResult = $statement-&gt;execute();\necho mysqli_affected_rows($conn);\nmysqli_close($conn);\n?&gt;\n<\/code><\/pre>\n<h2>Event management calendar output<\/h2>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-large wp-image-20543\" src=\"https:\/\/phppot.com\/wp-content\/uploads\/2023\/03\/event-management-in-php-550x480.jpg\" alt=\"event management in php\" width=\"550\" height=\"480\" srcset=\"https:\/\/phppot.com\/wp-content\/uploads\/2023\/03\/event-management-in-php-550x480.jpg 550w, https:\/\/phppot.com\/wp-content\/uploads\/2023\/03\/event-management-in-php-300x262.jpg 300w, https:\/\/phppot.com\/wp-content\/uploads\/2023\/03\/event-management-in-php-768x671.jpg 768w, https:\/\/phppot.com\/wp-content\/uploads\/2023\/03\/event-management-in-php.jpg 1200w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\"><\/p>\n<p><a class=\"download\" href=\"https:\/\/phppot.com\/downloads\/php\/event-management-in-php.zip\">Download<\/a><\/p>\n<p> <!-- #comments --> <\/p>\n<div class=\"related-articles\">\n<h2>Popular Articles<\/h2>\n<\/p><\/div>\n<p> <a href=\"https:\/\/phppot.com\/php\/event-management-system-in-php\/#top\" class=\"top\">\u2191 Back to Top<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>by Vincy. Last modified on March 10th, 2023. When managing events, the date and time come into the picture. So, the calendar component is the best to render events in a viewport. It is convenient compared to other views like card-view or list-view. This example uses the JavaScript library FullCalendar to render and manage events. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":132370,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[65],"tags":[],"class_list":["post-132369","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-updates"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/132369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=132369"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/132369\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media\/132370"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=132369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=132369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=132369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}