Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] Event Management System Project in PHP

#1
Event Management System Project in PHP

<div style="margin: 5px 5% 10px 5%;"><img src="https://www.sickgaming.net/blog/wp-content/uploads/2023/03/event-management-system-project-in-php.jpg" width="550" height="417" title="" alt="" /></div><div><div class="modified-on" readability="7.0909090909091"> by <a href="https://phppot.com/about/">Vincy</a>. Last modified on March 10th, 2023.</div>
<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>
<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>
<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>
<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>
<p><img 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/20...00x227.jpg 300w, https://phppot.com/wp-content/uploads/20...68x582.jpg 768w, https://phppot.com/wp-content/uploads/20...in-php.jpg 1200w" sizes="(max-width: 550px) 100vw, 550px"></p>
<h2>Step 1: Create an HTML base with the FullCalendar library</h2>
<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>
<ol>
<li>FullCalendar.</li>
<li>MomentJS.</li>
<li>jQuery and jQuery UI.</li>
</ol>
<p>It has an empty DIV target that will display the calendar UI after initiating the FullCalendar JavaScript library class.</p>
<p class="code-heading">index.php</p>
<pre class="prettyprint"><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&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;
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"&gt;&lt;/script&gt;
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/fullcalendar.min.js"&gt;&lt;/script&gt;
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/locale-all.js"&gt;&lt;/script&gt;
&lt;link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/fullcalendar.min.css" rel="stylesheet"&gt;
&lt;link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css"&gt;
&lt;link rel="stylesheet" href="assets/css/style.css"&gt;
&lt;link rel="stylesheet" href="assets/css/form.css"&gt;
&lt;script src="assets/js/event.js"&gt;&lt;/script&gt;
&lt;style&gt;
.btn-event-delete { font-size: 0.85em; margin: 0px 10px 0px 5px; font-weight: bold; color: #959595;
}
&lt;/style&gt;
&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;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<h2>Step 2: Create MySQL Structure in phpMyAdmin</h2>
<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>
<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>
<ol>
<li>Create a database and import the below SQL script into it.</li>
<li>Configure the newly created database in config/db.php of this project.</li>
</ol>
<h3>Database script</h3>
<p class="code-heading">sql/structure.sql</p>
<pre class="prettyprint"><code class="language-sql">--
-- Database: `full_calendar`
-- -- -------------------------------------------------------- --
-- Table structure for table `tbl_events`
-- 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
) ENGINE=InnoDB DEFAULT CHARSET=latin1; --
-- Indexes for dumped tables
-- --
-- Indexes for table `tbl_events`
--
ALTER TABLE `tbl_events` ADD PRIMARY KEY (`id`); --
-- AUTO_INCREMENT for dumped tables
-- --
-- AUTO_INCREMENT for table `tbl_events`
--
ALTER TABLE `tbl_events` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
</code></pre>
<h3>Database configuration</h3>
<p class="code-heading">db.php</p>
<pre class="prettyprint"><code class="language-php">&lt;?php
$conn = mysqli_connect("localhost", "root", "", "full_calendar"); if (! $conn) { echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?&gt;
</code></pre>
<h2>Step 3: Initiate Fullcalendar and create listeners to manage events</h2>
<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>
<ol>
<li>editable – It will enable event editing on the calendar by switching it on.</li>
<li>droppable – It supports event <a href="https://phppot.com/jquery/jquery-drag-and-drop/">drag and drops</a> to change the date.</li>
<li>eventResize – It supports inline extending or reducing the event period by resizing.</li>
<li>eventLimit – It allows limiting the number of events displayed on a date instance.</li>
<li>displayEventTime – It shows event time if added.</li>
</ol>
<p>The Fullcalendar property “events” 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>
<p>This script maps the calendar event’s select, drag, drop, and resize with the defined <a href="https://phppot.com/php/ajax-programming-with-php/">AJAX handlers</a>.</p>
<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();
});
function 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"); } });
} 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"); } });
} 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"); } } });
}
function displayMessage(message) { $(".response").html("&lt;div class='success'&gt;" + message + "&lt;/div&gt;"); setInterval(function() { $(".success").fadeOut(); }, 5000);
} function filterEvent() { var filterVal = $("#filter").val(); if (filterVal) { $('#calendar').fullCalendar('gotoDate', filterVal); $("#filter").val(""); }
}
</code></pre>
<h2>Step 4: Create AJAX endpoints to create, render and manage event data</h2>
<p>This section shows the PHP code for the AJAX endpoint. The Fullcalendar callback handlers call these endpoints via AJAX.</p>
<p>This endpoint receives the event title, start date, and end date. It processes the requested database operation using the received parameters.</p>
<p class>ajax-endpoint/fetch-calendar.php</p>
<pre class="prettyprint"><code class="language-php">&lt;?php
require_once "../config/db.php"; $json = array();
$sql = "SELECT * FROM tbl_events ORDER BY id"; $statement = $conn-&gt;prepare($sql);
$statement-&gt;execute();
$dbResult = $statement-&gt;get_result(); $eventArray = array();
while ($row = mysqli_fetch_assoc($dbResult)) { array_push($eventArray, $row);
}
mysqli_free_result($dbResult); mysqli_close($conn);
echo json_encode($eventArray);
?&gt;
</code></pre>
<p class>ajax-endpoint/add-calendar.php</p>
<pre class="prettyprint"><code class="language-php">&lt;?php
require_once "../config/db.php"; $title = $_POST['title'];
$start = $_POST['start'];
$end = $_POST['end'];
$statement = $conn-&gt;prepare('INSERT INTO tbl_events (title,start,end) VALUES (?,?,?)');
$statement-&gt;bind_param('sss', $title, $start, $end);
$rowResult = $statement-&gt;execute();
if (! $rowResult) { $result = mysqli_error($conn);
}
?&gt;
</code></pre>
<p class>ajax-endpoint/edit-calendar.php</p>
<pre class="prettyprint"><code class="language-php">&lt;?php
require_once "../config/db.php"; $id = $_POST['id'];
$title = $_POST['title'];
$start = $_POST['start'];
$end = $_POST['end'];
$statement = $conn-&gt;prepare('UPDATE tbl_events SET title = ?, start= ?, end=? WHERE id = ?');
$statement-&gt;bind_param('sssi', $title, $start, $end, $id);
$rowResult = $statement-&gt;execute();
mysqli_close($conn);
?&gt;
</code></pre>
<p class>ajax-endpoint/delete-calendar.php</p>
<pre class="prettyprint"><code class="language-php">&lt;?php
require_once "../config/db.php"; $id = $_POST['id'];
$statement = $conn-&gt;prepare('DELETE from tbl_events WHERE id= ?');
$statement-&gt;bind_param('i', $id);
$rowResult = $statement-&gt;execute();
echo mysqli_affected_rows($conn);
mysqli_close($conn);
?&gt;
</code></pre>
<h2>Event management calendar output</h2>
<p><img 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/20...00x262.jpg 300w, https://phppot.com/wp-content/uploads/20...68x671.jpg 768w, https://phppot.com/wp-content/uploads/20...in-php.jpg 1200w" sizes="(max-width: 550px) 100vw, 550px"></p>
<p><a class="download" href="https://phppot.com/downloads/php/event-management-in-php.zip">Download</a></p>
<p> <!-- #comments --> </p>
<div class="related-articles">
<h2>Popular Articles</h2>
</p></div>
<p> <a href="https://phppot.com/php/event-management-system-in-php/#top" class="top">↑ Back to Top</a> </p>
</div>


https://www.sickgaming.net/blog/2023/03/...ct-in-php/
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016