/    Sign up×
Community /Pin to ProfileBookmark

PHP Mysql Javascript Calendar Event Delete and Edit

Hi,

Good day!

I found a tutorial on creating a calendar that can add Event.

Now, I want to enhance it to add Delete and Edit button but I have no idea on how to do that here is my code:

calendar.php

[code=php]
<?php
$hostname = ‘localhost’;
$username = ‘root’;
$password = ‘root’;
$dbname = ‘calendar’;

$conn = new mysqli($hostname, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
<script>
function goLastMonth(month,year)
{
if(month == 1)
{
–year;
month = 13;
}
–month
var monthstring = “”+month+””;
var monthlength = monthstring.length;
if(monthlength <= 1)
{
monthstring = “0”+monthstring;
}

document.location.href = “<?php $_SERVER[‘PHP_SELF’];?>?month=”+monthstring+”&year=”+year;
}

function goNextMonth(month,year)
{
if(month == 12)
{
++year;
month = 0;
}
++month
var monthstring = “”+month+””;
var monthlength = monthstring.length;
if(monthlength <= 1)
{
monthstring = “0”+monthstring;
}
document.location.href = “<?php $_SERVER[‘PHP_SELF’];?>?month=”+monthstring+”&year=”+year;
}
</script>

<style>
.today { background-color: #d3c6bd; }
.event { background-color: #8d735a; }
</style>
</head>

<body>
<?php
if(isset($_GET[‘day’]))
{
$day = $_GET[‘day’];
}else{
$day = date(“j”);
}

if(isset($_GET[‘month’]))
{
$month = $_GET[‘month’];
}else{
$month = date(“n”);
}

if(isset($_GET[‘year’]))
{
$year = $_GET[‘year’];
}else{
$year = date(“Y”);
}

$maxDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
if( $day > $maxDay ) {
$day = $maxDay;
}

$currentTimeStamp = strtotime(“$year-$month-$day”);

$monthName = date(“F”, $currentTimeStamp);

$numDays = date(“t”, $currentTimeStamp);

$counter = 0;

if(isset($_GET[‘add’]))
{
$title = $_POST[‘txttitle’];
$detail = $_POST[‘txtdetail’];
$eventdate = $month.”/”.$day.”/”.$year;

$sqlinsert = “INSERT INTO tbl_calendar (Title, Detail, eventDate, dateAdded)
VALUES (‘”.$title.”‘,'”.$detail.”‘,'”.$eventdate.”‘, now())”;
if ($conn->query($sqlinsert) === TRUE) {
// echo “Event was successfully Added…”;
}
else
{
// echo “Event Failed to be Added…”;
}

}
?>
<table border=”1″>
<tr>
<td><input style=’width:60px; height:40px;’ type=’button’ value='<‘ name=’previousbutton’ onClick=”goLastMonth(<?php echo $month.”,”.$year; ?>);”></td>
<td colspan=”5″ style=’text-align:center;font-weight:bold;background-color:#8d735a; color:#FFF;’><?php echo $monthName. “, “.$year; ?></td>
<td><input style=’width:60px; height:40px;’ type=’button’ value=’>’ name=’nextbutton’ onClick=”goNextMonth(<?php echo $month.”,”.$year; ?>);”></td>
</tr>

<tr style=’background-color:#af9c8e; color:white;’>
<td width=’60px’ height=’40px’ align=’center’>Sun</td>
<td width=’60px’ height=’40px’ align=’center’>Mon</td>
<td width=’60px’ height=’40px’ align=’center’>Tue</td>
<td width=’60px’ height=’40px’ align=’center’>Wed</td>
<td width=’60px’ height=’40px’ align=’center’>Thu</td>
<td width=’60px’ height=’40px’ align=’center’>Fri</td>
<td width=’60px’ height=’40px’ align=’center’>Sat</td>
</tr>
<?php
echo “<tr>”;

for($i = 1; $i < $numDays+1; $i++, $counter++){
$timeStamp = strtotime(“$year-$month-$i”);
if($i == 1)
{
$firstDay = date(“w”, $timeStamp);

for($j = 0; $j < $firstDay; $j++, $counter++)
{
echo “<td>&nbsp;</td>”;
}
}
if($counter % 7 == 0)
{
echo “</tr><tr>”;
}
$monthstring = $month;
$monthlength = strlen($monthstring);
$daystring = $i;
$daylength = strlen($daystring);
if($monthlength <=1)
{
$monthstring = “0”.$monthstring;
}
if($daylength <=1)
{
$daystring = “0”.$daystring;
}

$todaysDate = date(“m/d/Y”);
$dateToCompare = $monthstring.’/’.$daystring.’/’.$year;

echo “<td align=’center’ width=’60px’ height=’40px'”;
if($todaysDate == $dateToCompare)
{
echo “class=’today'”;
}
else
{
$sqlCount = “SELECT * from tbl_calendar where eventDate='”.$dateToCompare.”‘”;
$resCount = $conn->query($sqlCount);
$noOfEvent = $resCount->num_rows;
if($noOfEvent >= 1){
echo “class=’event'”;
}

}
echo “><a href='”.$_SERVER[‘PHP_SELF’].”?month=”.$monthstring.”&day=”.$daystring.”&year=”.$year.”&v=true’ style=’text-decoration:none; color:#000;’>”.$i.”</a></td>”;
}

echo “</tr>”;
?>
</table>
<br/>
<?php
if(isset($_GET[‘v’]))
{
echo “<a href='”.$_SERVER[‘PHP_SELF’].”?month=”.$month.”&day=”.$day.”&year=”.$year.”&v=true&f=true’ style=’float:left; margin:-390px auto auto 500px; background-color:#83694d; padding:5px; border-color:#fece99; border-radius:4px; color:white; cursor:pointer; width:58px; text-decoration:none; font-weight:bold;’>Add Event</a>”;
if(isset($_GET[‘f’]))
{
include(“eventform.php”);
}
$sqlEvent = “SELECT * FROM tbl_calendar WHERE eventDate = ‘”.$month.”/”.$day.”/”.$year.”‘”;
$resEvent = $conn->query($sqlEvent);
$cntEvent = $resEvent->num_rows;

echo “<br/>”;
if(isset($_GET[‘f’]))
{
echo “<div style=’float:left; margin:-150px auto auto 500px;’>”;
}
else
{
echo “<div style=’float:left; margin:-370px auto auto 500px;’>”;
}

while($row= $resEvent->fetch_array())
{
echo “<b>Title: </b>”. $row[‘Title’].”<br/>”;
echo “<b>Detail: </b>”. $row[‘Detail’].”<br/>”;
}
echo “</div>”;
}
?>
</body>
</html>
[/code]

eventform.php

[code=php]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>

<body>
<form name=’eventform’ method=’POST’ action=”<?php $_SERVER[‘PHP_SELF’]; ?>?month=<?php echo $month;?>&day=<?php echo $day; ?>&year=<?php echo $year; ?>&v=true&add=true”>
<div style=”float:left; margin:-360px auto auto 500px;”>
<table width=’400px’>
<tr>
<td width=’50px’ style=’font-weight:bold;’>Title: </td>
<td width=’250px’><input type=’text’ name=’txttitle’ size=’40’></td>
</tr>
<tr>
<td width=’50px’ style=’font-weight:bold;’>Detail: </td>
<td width=’250px’><textarea name=’txtdetail’ style=’width: 300px; height: 150px;’> </textarea></td>
</tr>
<tr>
<td colspan=’2′ align=’center’><input type=’submit’ name=’btnadd’ value=’Submit’ style=’width:80px; height:25px; background-image:url(images/Search-Button.jpg); border-radius:5px; border: 1px solid #616f7c; color:#fff; margin: auto;cursor:pointer;’></td>
</tr>

</table>
</div>
</form>
</body>
</html>
[/code]

Thank you

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @newphpcoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...