• (3 Pages)
  • +
  • 1
  • 2
  • 3

Event Tracking Calendar Rate Topic: ***** 1 Votes

#1 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Posted 19 February 2009 - 11:25 PM

Building an Event Tracking Calendar


I have seen this question posted over and over again here, yet nobody has thoroughly answered this question. I wrote this tutorial so that new members to this site will have the opportunity to have their calendar scripts taken to the next level.

In this tutorial, I will show you how to create a calendar application that has the ability to add / remove events on a given day. We will be using MySQL as our database application to store and track events.

This tutorial is written for people who understand basic programming theory, and some of the PHP structure. I will discuss the beginner (and some more advanced) techniques, and apply them in a real world application.


Requirements:
- Programming Logic
- Basic PHP knowledge
- Basic Javascript knowledge
- PHP supported server
- MySQL server
- 2 files (calendar.php and event.php)
- Notepad (or IDE of choice)

Index:
  • Section 1
    • Part 1 - Checking User Input
    • Part 2 - Building the HTML Form
    • Part 3 - Creating the Calendar
  • Section 2
    • Part 4 - Adding Events to the Calendar
    • Part 5 - Showing / Adding Events via. Pop-Up



Section 1 - Building the Calendar

Part 1 - Checking User Input

We will be asking the user for the month and year that they want to view of the calendar, so the first thing we need to do is figure out what part of the calendar will be generated. When the user views the calendar for the first time, we will not have any information, so we need to tell the script how to handle accepting the variables for the month and year.

- Checking User Input for the Calendar Script:

<?php
if ((!isset($_POST['month'])) || (!isset($_POST['year']))) {
	$nowArray = getdate();
	$month = $nowArray['mon'];
	$year = $nowArray['year'];
} else {
	$month = $_POST['month'];
	$year = $_POST['year'];
}
$start = mktime(12,0,0,$month,1,$year);
$firstDayArray = getdate($start);
?>




What we are doing here is first, checking if the user has submitted any information. If they have, we will take the $_POST['month']; and $_POST['year']; variables and store them for processing. If they haven't submitted any form data, we know that this must be the first time they have loaded our application, and we will set the selected date and year as the current.

The function mktime(); is used to easily format string data (our $_POST variables) as a UNIX Timestamp.

We also used getdate(); as seen on line 3, to create an associative array based on the current time.


Part 2 - Building the HTML Form

Now that we have our method of accepting the users input using PHP, we need to create an interface by which users can select the month and year. We will be using pull down menus, also known as the SELECT element in HTML. We could use HTML to do this, but since we want to keep our menu at the currently selected month / year, we will use PHP to dynamically create the menu.

<html>
<head>
<title><?php echo "Calendar: ".$firstDayArray['month']."" . $firstDayArray['year']; ?></title>
</head>
<body>
<h1>Select a Month/Year</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

for ($x=1; $x<=count($months); $x++){
	echo "<option value=\"$x\"";
	if ($x == $month){
		echo " selected";
	}
	echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select name="year">
<?php
for ($x=1980; $x<=2010; $x++){
	echo "<option";
	if ($x == $year){
		echo " selected";
	}
	echo ">$x</option>";
}
?>
</select>
<input type="submit" name="submit" value="Go!">
</form>
</body>
</html>



The main theory here is our for(){}; loop. As previously mentioned, instead of using HTML to hard-code the months as static information, we are using PHP to create an array that stores the months of the year. Doing so, we can use our $_POST information to keep the corresponding month / year selected throughout the process (until it is changed by the user).

Also, we can see the use of dynamic content on our page. Notice the <title> contains our month and year. Small things like this all add up to making a dynamic, and nice looking page.


So we now have a form that can send the month and year parameters to itself.

Part 3 - Creating the Calendar

Now that we have completed the selection menu, we are ready to build the calendar. PHP has no built in calendar(); functions, so we will need to create a table and populate it with the corresponding days manually.

<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<table border=\"1\" cellpadding=\"3\"><tr>\n";
foreach ($days as $day){
	echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14% \"><strong>$day</strong></td>\n";
}
for ($count=0; $count < (6*7); $count++){
	$dayArray = getdate($start);
	if (($count % 7) == 0){
		if ($dayArray['mon'] != $month){
			break;
		} else {
			echo "</tr><tr>\n";
		}
	}
	if ($count < $firstDayArray['wday'] || $dayArray['mon'] != $month){
		echo "<td></td>\n";
	} else {
		echo "<td>".$dayArray['mday']."  </td>\n";
		$start += ADAY;
	}
}
echo "</tr></table>";
?>
</body>
</html>



Here, we are using a for loop to determine how many days are in each week, and what days need to be printed along the way. As far as the logic goes, this is the same as any other loop, with specific conditions that detail where things go where they need to go.

Code so far:

<?php
if ((!isset($_POST['month'])) || (!isset($_POST['year']))) {
	$nowArray = getdate();
	$month = $nowArray['mon'];
	$year = $nowArray['year'];
} else {
	$month = $_POST['month'];
	$year = $_POST['year'];
}
$start = mktime(12,0,0,$month,1,$year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php echo "Calendar: ".$firstDayArray['month']."" . $firstDayArray['year']; ?></title>
</head>
<body>
<h1>Select a Month/Year</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

for ($x=1; $x<=count($months); $x++){
	echo "<option value=\"$x\"";
	if ($x == $month){
		echo " selected";
	}
	echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select name="year">
<?php
for ($x=1980; $x<=2010; $x++){
	echo "<option";
	if ($x == $year){
		echo " selected";
	}
	echo ">$x</option>";
}
?>
</select>
<input type="submit" name="submit" value="Go!">
</form>
<br />
<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<table border=\"1\" cellpadding=\"3\"><tr>\n";
foreach ($days as $day){
	echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14% \"><strong>$day</strong></td>\n";
}
for ($count=0; $count < (6*7); $count++){
	$dayArray = getdate($start);
	if (($count % 7) == 0){
		if ($dayArray['mon'] != $month){
			break;
		} else {
			echo "</tr><tr>\n";
		}
	}
	if ($count < $firstDayArray['wday'] || $dayArray['mon'] != $month){
		echo "<td></td>\n";
	} else {
		echo "<td>".$dayArray['mday']."  </td>\n";
		$start += ADAY;
	}
}
echo "</tr></table>";
?>
</body>
</html>



This calendar is all pretty and nice, but it is missing something. We are here to learn how to add events to a calendar... which is where we go next!


Section 2 - Database Driven Events

This second part is an extention to the Calendar Script. The calendar as it is up to this point is 100% functional and can stand alone without continuing. The point of the second section is: to teach you how to modify what you've done by using MySQL and a bit more advanced PHP, to create a Calendar Management System to track events.

Part 4 - Adding Events to the Calendar

First things first, as you most likely already know, we need a database. The purpose of the database is to store our events, and deliver dynamic content to our calendar application. In this tutorial, we will be using MySQL.

The calendar_events table will have fields for the start date and time, the name of the event, and a short description of the event.

CREATE TABLE calendar_events (
	id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
	event_title VARCHAR (25),
	event_shortdesc VARCHAR (255),
	event_start DATETIME
);



Now that we have created our database table, we are ready to start the design of adding events. By my personal preference, I decided that the events will load in a small pop-out window. I like the way this looks / acts better than navigating away from our actual calendar... but if you should choose to do so otherwise, this would be a small fix. I won't cover this here, but it shouldn't be too hard to figure out :)

<script type="text/javascript">
function eventWindow(url){
	event_popupWin = window.open(url, 'event', 'resizable=yes, scrollbars=yes, toolbar=no,width=400,height=400');
	event_popupWin.opener = self;
}
</script>



This code as you can see simply defines the window attributes that will open when we are ready to view our events.

The next step we must take is to modify the Calendar creation script to add Hyperlink URL's on the days to show / add events. Furthermore, we must design a system that connects to our MySQL database and prints any events on the calendar so we can see which days have stored events. This will require some modifications, mostly around lines 64-68.

calendar.php
<?php
// At line 2 of our calendar.php script, add the MySQL connection information:
$mysql = mysql_connect("localhost", "username", "password");
mysql_select_db("database_name", $mysql) or die(mysql_error());

// Now we need to define "A DAY", which will be used later in the script:
define("ADAY", (60*60*24));

// The rest of the script will stay the same until about line 82

if ((!isset($_POST['month'])) || (!isset($_POST['year']))) {
	$nowArray = getdate();
	$month = $nowArray['mon'];
	$year = $nowArray['year'];
} else {
	$month = $_POST['month'];
	$year = $_POST['year'];
}
$start = mktime(12,0,0,$month,1,$year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php echo "Calendar: ".$firstDayArray['month']."" . $firstDayArray['year']; ?></title>
</head>
<script type="text/javascript">
function eventWindow(url) {
	event_popupWin = window.open(url, 'event', 'resizable=yes,scrollbars=yes,toolbar=no,width=400,height=400');
	event_popupWin.opener = self;
}
</script>
<body>
<h1>Select a Month/Year</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

for ($x=1; $x<=count($months); $x++){
	echo "<option value=\"$x\"";
	if ($x == $month){
		echo " selected";
	}
	echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select name="year">
<?php
for ($x=1980; $x<=2010; $x++){
	echo "<option";
	if ($x == $year){
		echo " selected";
	}
	echo ">$x</option>";
}
?>
</select>
<input type="submit" name="submit" value="Go!">
</form>
<br />
<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<table border=\"1\" cellpadding=\"5\"><tr>\n";
foreach ($days as $day) {
	echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14%\">
	      <strong>$day</strong></td>\n";
}

for ($count=0; $count < (6*7); $count++) {
	$dayArray = getdate($start);
	if (($count % 7) == 0) {
		if ($dayArray["mon"] != $month) {
			break;
		} else {
			echo "</tr><tr>\n";
		}
	}
	if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) {
		echo "<td></td>\n";
	} else {
		$chkEvent_sql = "SELECT event_title FROM calendar_events WHERE month(event_start) = '".$month."' AND dayofmonth(event_start) = '".$dayArray["mday"]."' AND year(event_start) = '".$year."' ORDER BY event_start";
		$chkEvent_res = mysql_query($chkEvent_sql, $mysql) or die(mysql_error($mysql));

		if (mysql_num_rows($chkEvent_res) > 0) {
			$event_title = "<br/>";
			while ($ev = mysql_fetch_array($chkEvent_res)) {
				$event_title .= stripslashes($ev["event_title"])."<br/>";
			}
			mysql_free_result($chkEvent_res);
		} else {
			$event_title = "";
		}

		echo "<td valign=\"top\"><a href=\"java script:eventWindow('event.php?m=".$month."&d=".$dayArray["mday"]."&y=$year');\">".$dayArray["mday"]."</a><br/>".$event_title."</td>\n";

		unset($event_title);

		$start += ADAY;
	}
}
echo "</tr></table>";
mysql_close($mysql);
?>
</body>
</html>




Now that we have modified everything in the calendar script to support Events, the only thing left to do is add our event.php script! This will take most of the basic principals we have already discussed and use them to add data to our database. Since our Calendar already supports database driven content, this will be the last step in our process!

Part 5 - Showing / Adding Events via. Pop-Up

Create a new file called: event.php

<html>
<head>
<title>Show / Add Events</title>
</head>
<body>
<h1>Show / Add Events</h1>
<?php
$mysql = mysql_connect("localhost", "username", "password");
mysql_select_db("database_name", $mysql) or die(mysql_error());

// Add our new events
if ($_POST){
	$m = $_POST['m'];
	$d = $_POST['d'];
	$y = $_POST['y'];

	// Formatting for SQL datetime (if this is edited, it will NOT work.)
	$event_date = $y."-".$m."-".$d." ".$_POST["event_time_hh"].":".$_POST["event_time_mm"].":00";

	$insEvent_sql = "INSERT INTO calendar_events (event_title,
			event_shortdesc, event_start) VALUES('
			".$_POST["event_title"]."',
			'".$_POST["event_shortdesc"]."', '$event_date')";
	$insEvent_res = mysql_query($insEvent_sql, $mysql)
			or die(mysql_error($mysql));
} else {
	$m = $_GET['m'];
	$d = $_GET['d'];
	$y = $_GET['y'];
}
// Show the events for this day:
$getEvent_sql = "SELECT event_title, event_shortdesc,
		date_format(event_start, '%l:%i %p') as fmt_date FROM
		calendar_events WHERE month(event_start) = '".$m."'
		AND dayofmonth(event_start) = '".$d."' AND
		year(event_start)= '".$y."' ORDER BY event_start";
$getEvent_res = mysql_query($getEvent_sql, $mysql)
		or die(mysql_error($mysql));

if (mysql_num_rows($getEvent_res) > 0){
	$event_txt = "<ul>";
	while($ev = @mysql_fetch_array($getEvent_res)){
		$event_title = stripslashes($ev["event_title"]);
		$event_shortdesc = stripslashes($ev["event_shortdesc"]);
		$fmt_date = $ev["fmt_date"];
		$event_txt .= "<li><strong>".$fmt_date."</strong>:
			      ".$event_title."<br/>".$event_shortdesc."</li>";
	}
	$event_txt .="</ul>";
	mysql_free_result($getEvent_res);
} else {
	$event_txt = "";
}

mysql_close($mysql);

if ($event_txt != ""){
	echo "<p><strong>Today's Events:</strong></p>
	$event_txt
	<hr/>";
}

// Show form for adding the event:

echo "
<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">
<p><strong>Add Event:</strong><br/>
Complete the form below then press the submit button when you are done.</p>
<p><strong>Event Title:</strong><br/>
<input type=\"text\" name=\"event_title\" size=\"25\" maxlength=\"25\"/></p>
<p><strong>Event Description:</strong<br/>
<input type=\"text\" name=\"event_shortdesc\" size=\"25\" maxlength=\"255\"/></p>
<p><strong>Event Time (hh:mm):</strong><br/>
<select name=\"event_time_hh\">";
for ($x=1; $x<=24; $x++){
	echo "<option value=\"$x\">$x</option>";
}
echo "</select> :
<select name=\"event_time_mm\">
<option value=\"00\">00</option>
<option value=\"15\">15</option>
<option value=\"30\">30</option>
<option value=\"45\">45</option>
</select>
<input type=\"hidden\" name=\"m\" value=\"".$m."\">
<input type=\"hidden\" name=\"d\" value=\"".$d."\">
<input type=\"hidden\" name=\"y\" value=\"".$y."\">
<br/><br/>
<input type=\"submit\" name=\"submit\" value=\"Add Event!\">
</form>";
?>
</body>
</html>



There we have it! Lines 29-35 send the query and return all the records that correspond to events on the given day. We display the entries on lines 37-51. The form for submitting new events can be found on lines 61-87.


I would like to thank everyone at D.I.C. for this article. I have been programming for almost 12 years now, and without D.I.C. I wouldn't have kept a solid interest in programming. I am now re-attending college for my Computer Science degree, and I'm leaps and bounds above most of the people in the program. This summer I am joining a robotics team as the main physics and collision detection programmer... so look forward to seeing more and more tutorials from things I learn along the way!

Is This A Good Question/Topic? 3
  • +

Replies To: Event Tracking Calendar

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1637
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Posted 19 February 2009 - 11:42 PM

In my mind this is a very nice tutorial, though I might think about working on some of the formatting, like indenting code, but the content is nice :)
Was This Post Helpful? 0
  • +
  • -

#3 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Posted 20 February 2009 - 12:26 AM

Strange... The code is 100% perfectly indented for me. I think you are experiencing the Syntax Highlighting problem on the site. For some reason, about 50% of the time... all code loses it's syntax highlighting and indenting. Sky said it was Google's software that was the problem, but I'm not sure.

I'll check the indenting on the code and make sure I posted the right stuff, but I'm almost positive I did.
Was This Post Helpful? 0
  • +
  • -

#4 dreadfear  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 180
  • Joined: 08-December 08

Posted 15 July 2009 - 09:25 PM

Thanks, wasnt sure how to go about this. This helps alot :)
Was This Post Helpful? 0
  • +
  • -

#5 Guest_bacondo*


Reputation:

Posted 29 March 2010 - 04:03 PM

the form for adding an event dosent show?
Was This Post Helpful? 0

#6 Guest_everythingis*


Reputation:

Posted 03 April 2010 - 07:29 PM

I had to remove a couple things that were giving me errors, so hopefully this will help someone else out:

Remove the mysql variable in all of these areas:
$chkEvent_res = mysql_query($chkEvent_sql)

mysql_close(); 


Same on event.php:
$insEvent_res = mysql_query($insEvent_sql)

$getEvent_res = mysql_query($getEvent_sql)

mysql_close(); 


Here are some ideas to make it a little better:

Add this on event.php to show the date of the event within the pop-up:
<h1><?php 
	if ($_POST){
		echo $_POST['m']." / " .  $_POST['d']." / " . $_POST['y'];
	}
	else {
		echo $_GET['m']." / " . $_GET['d']." / " . $_GET['y'];
		} 
?></h1> 



add this on event.php to make it a 12 hour event time and use AM/PM:
	if ($_POST['event_time_ampm'] == '12') {      
		$_POST['event_time_hh'] = $_POST['event_time_hh'] + 12;
	} else {
	$_POST['event_time_hh'];	
	}


<p><strong>Event Time:</strong><br/> 
<select name=\"event_time_hh\">"; 
for ($x=1; $x<=12; $x++){ 
        echo "<option value=\"$x\">$x</option>"; 
} 
echo "</select> : 
<select name=\"event_time_mm\"> 
<option value=\"00\">00</option> 
<option value=\"15\">15</option> 
<option value=\"30\">30</option> 
<option value=\"45\">45</option> 
</select> 


<select name=\"event_time_ampm\"> 
<option value=\"00\">AM</option> 
<option value=\"12\">PM</option> 
</select> 



Add this on calendar.php to make the year automatically adjust & update itself:
$thisYear = date('Y');



<select name="year"> 
<?php 
for ($x=$thisYear - 70; $x<=$thisYear + 15; $x++){ 
        echo "<option"; 
        if ($x == $year){ 
                echo " selected"; 
        } 
        echo ">$x</option>"; 



I'm still working on it to be able to highlight the current day in the calendar, add more fields in the event form, edit & delete events, and make each individual event a link that can be opened individually.
Was This Post Helpful? 0

#7 Guest_Chris*


Reputation:

Posted 21 September 2010 - 06:18 AM

Hi

After many days trying to crack the code for events calendar, i happened across your page.

Just like to say thanks so much for giving me the ideas i needed to accomplish my page

Chris
Was This Post Helpful? 0

#8 Dannyboy997  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 64
  • View blog
  • Posts: 258
  • Joined: 17-April 09

Posted 21 September 2010 - 08:51 AM

good tutorial!

-Daniel
Was This Post Helpful? 0
  • +
  • -

#9 Guest_theophilus alamu*


Reputation:

Posted 09 December 2010 - 06:39 AM

this is just beautiful. working on how to include the entries on each date as links. think when i'm done i will post it.
Was This Post Helpful? 0

#10 Guest_scottryan*


Reputation:

Posted 02 February 2011 - 06:43 AM

Hi guys,
I followed the tutorial, but keep getting an error as followed:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ');"' ORDER BY event_start' at line 5


The only thing I have modified so far is instead of a js popup, I just go right to the event.php.
Thanks for your help.
Scott

<html>
<head>
<title>Show / Add Events</title>
</head>
<body>
<h1>Show / Add Events</h1>
<?php
$mysql = mysql_connect("localhost", "root", "jesussaves");
mysql_select_db("egenda_db", $mysql) or die(mysql_error());

// Add our new events
if ($_POST){
	$m = $_POST['m'];
	$d = $_POST['d'];
	$y = $_POST['y'];

	// Formatting for SQL datetime (if this is edited, it will NOT work.)
	$event_date = $y."-".$m."-".$d." ".$_POST["event_time_hh"].":".$_POST["event_time_mm"].":00";

	$insEvent_sql = "INSERT INTO calendar_events (event_title,
			event_shortdesc, event_start) VALUES('
			".$_POST["event_title"]."',
			'".$_POST["event_shortdesc"]."', '$event_date')";
	$insEvent_res = mysql_query($insEvent_sql)
			or die(mysql_error());
} else {
	$m = $_GET['m'];
	$d = $_GET['d'];
	$y = $_GET['y'];
}
// Show the events for this day:
$getEvent_sql = "SELECT event_title, event_shortdesc,
		date_format(event_start, '%l:%i %p') as fmt_date FROM
		calendar_events WHERE month(event_start) = '".$m."'
		AND dayofmonth(event_start) = '".$d."' AND
		year(event_start) = '".$y."' ORDER BY event_start";
$getEvent_res = mysql_query($getEvent_sql)
		or die(mysql_error());

if (mysql_num_rows($getEvent_res) > 0){
	$event_txt = "<ul>";
	while($ev = @mysql_fetch_array($getEvent_res)){
		$event_title = stripslashes($ev["event_title"]);
		$event_shortdesc = stripslashes($ev["event_shortdesc"]);
		$fmt_date = $ev["fmt_date"];
		$event_txt .= "<li><strong>".$fmt_date."</strong>:
			      ".$event_title."<br/>".$event_shortdesc."</li>";
	}
	$event_txt .="</ul>";
	mysql_free_result($getEvent_res);
} else {
	$event_txt = "";
}

mysql_close();

if ($event_txt != ""){
	echo "<p><strong>Today's Events:</strong></p>
	$event_txt
	<hr/>";
}

// Show form for adding the event:

echo "
<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">
<p><strong>Add Event:</strong><br/>
Complete the form below then press the submit button when you are done.</p>
<p><strong>Event Title:</strong><br/>
<input type=\"text\" name=\"event_title\" size=\"25\" maxlength=\"25\"/></p>
<p><strong>Event Description:</strong<br/>
<input type=\"text\" name=\"event_shortdesc\" size=\"25\" maxlength=\"255\"/></p>
<p><strong>Event Time (hh:mm):</strong><br/>
<select name=\"event_time_hh\">";
for ($x=1; $x<=24; $x++){
	echo "<option value=\"$x\">$x</option>";
}
echo "</select> :
<select name=\"event_time_mm\">
<option value=\"00\">00</option>
<option value=\"15\">15</option>
<option value=\"30\">30</option>
<option value=\"45\">45</option>
</select>
<input type=\"hidden\" name=\"m\" value=\"".$m."\">
<input type=\"hidden\" name=\"d\" value=\"".$d."\">
<input type=\"hidden\" name=\"y\" value=\"".$y."\">
<br/><br/>
<input type=\"submit\" name=\"submit\" value=\"Add Event!\">
</form>";
?>
</body>
</html>




Was This Post Helpful? 0

#11 scottryan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-January 11

Posted 02 February 2011 - 11:17 AM

Alright after coming back to it with some fresh eyes, I got it. It was in calendar.php
It is the following line of code in the calendar.php file. Around line #90. Right where year is, I deleted '); right after year. Hope this helps someone else.
The code below is how it should be.
Scott

echo "<td valign=\"top\"><a href=event.php?m=".$month."&d=".$dayArray["mday"]."&y=$year\">".$dayArray["mday"]."</a><br/>".$event_title."</td>\n";


This post has been edited by scottryan: 02 February 2011 - 11:20 AM

Was This Post Helpful? 0
  • +
  • -

#12 Eluway  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 29-June 11

Posted 29 June 2011 - 03:33 AM

So I followed the tutorial and perhaps it's because I'm really tired but I can't get it to work. I keep getting the following error

"Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/fallenpeopleadmin/fallenpeople.com/events/calendar.php on line 85"

I'm not sure what I'm doing wrong. Here is my calendar.php code as is. I'd really appreciate any help


<?php
// At line 2 of our calendar.php script, add the MySQL connection information:
$mysql = mysql_connect("fallensql.fallenpeople.com", "descentadmin", "effinggoths");
mysql_select_db("fpe_calendar", $mysql) or die(mysql_error());
"CREATE TABLE `fpe_calendar`.`calendar.events` (`event_title` VARCHAR(50) NOT NULL, `event_shortdesc` VARCHAR(500) NOT NULL, `fmt_date` VARCHAR(50) NOT NULL, `event_local` VARCHAR(100) NOT NULL, `event_link` VARCHAR(200) NOT NULL) ENGINE = MyISAM;";

// Now we need to define "A DAY", which will be used later in the script:
define("ADAY", (60*60*24));



// The rest of the script will stay the same until about line 82
if ((!isset($_POST['month'])) || (!isset($_POST['year']))) {
	$nowArray = getdate();
	$month = $nowArray['mon'];
	$year = $nowArray['year'];
} else {
	$month = $_POST['month'];
	$year = $_POST['year'];
}
$start = mktime(12,0,0,$month,1,$year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php echo "Calendar: ".$firstDayArray['month']."" . $firstDayArray['year']; ?></title>
</head>
<script type="text/javascript">
function eventWindow(url) {
	event_popupWin = window.open(url, 'event.php', 'resizable=yes,scrollbars=yes,toolbar=no,width=400,height=400');
	event_popupWin.opener = self;
}
</script>
<body>
<h1>Select a Month/Year</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

for ($x=1; $x<=count($months); $x++){
	echo "<option value=\"$x\"";
	if ($x == $month){
		echo " selected";
	}
	echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select name="year">
<?php
for ($x=2011; $x<=2020; $x++){
	echo "<option";
	if ($x == $year){
		echo " selected";
	}
	echo ">$x</option>";
}
?>
</select>
<input type="submit" name="submit" value="Go!">
</form>
<br />
<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<table border=\"1\" cellpadding=\"5\"><tr>\n";
foreach ($days as $day) {
	echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14%\">
	      <strong>$day</strong></td>\n";
}

for ($count=0; $count < (6*7); $count++) {
	$dayArray = getdate($start);
	if (($count % 7) == 0) {
		if ($dayArray["mon"] != $month) {
			break;
		} else {
			echo "</tr><tr>\n";
		}
	}
	if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) {
		echo "<td>&nbsp;</td>\n";
	} else {
		$chkEvent_sql = "SELECT event_title FROM calendar_events WHERE month(event_start) = '".$month."' AND dayofmonth(event_start) = '".$dayArray["mday"]."' AND year(event_start) = '".$year."' ORDER BY event_start";
				$chkEvent_res = mysql_query($chkEvent_sql, mysql) or die(mysql_error());

		if (mysql_num_rows($chkEvent_res) > 0) {
			$event_title = "<br/>";
			while ($ev = mysql_fetch_array($chkEvent_res)) {
				$event_title .= stripslashes($ev["event_title"])."<br/>";
			}
			mysql_free_result($chkEvent_res);
		} else {
			$event_title = "";
		}

		echo "<td valign=\"top\"><a href=\"java script:eventWindow('event.php?m=".$month."&d=".$dayArray["mday"]."&y=$year');\">".$dayArray["mday"]."</a><br/>".$event_title."</td>\n";

		unset($event_title);

		$start += ADAY;
	}
}
echo "</tr></table>";
mysql_close();
?>
</body>
</html>


Was This Post Helpful? 0
  • +
  • -

#13 scottryan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 22-January 11

Posted 01 July 2011 - 06:36 AM

View PostEluway, on 29 June 2011 - 03:33 AM, said:

So I followed the tutorial and perhaps it's because I'm really tired but I can't get it to work. I keep getting the following error

"Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/fallenpeopleadmin/fallenpeople.com/events/calendar.php on line 85"

I'm not sure what I'm doing wrong. Here is my calendar.php code as is. I'd really appreciate any help


Hey Eluway,

Taking out all of the 'mysql' out will fix this problem. Here is what I have:

// Now we need to define "A DAY", which will be used later in the script:
define("ADAY", (60*60*24));

// The rest of the script will stay the same until about line 82

if ((!isset($_POST['month'])) || (!isset($_POST['year']))) {
	$nowArray = getdate();
	$month = $nowArray['mon'];
	$year = $nowArray['year'];
} else {
	$month = $_POST['month'];
	$year = $_POST['year'];
}
$start = mktime(12,0,0,$month,1,$year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php echo "Calendar: ".$firstDayArray['month']."" . $firstDayArray['year']; ?></title>
</head>
<body>
<h1>Select a Month/Year</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

for ($x=1; $x<=count($months); $x++){
	echo "<option value=\"$x\"";
	if ($x == $month){
		echo " selected";
	}
	echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select name="year">
<?php
$thisYear = date('Y');
for ($x=$thisYear - 0; $x<=$thisYear + 2; $x++){ 
        echo "<option"; 
        if ($x == $year){ 
                echo " selected"; 
        } 
        echo ">$x</option>"; 
}

?>
</select>
<input type="submit" name="submit" value="Go!">
</form>
<br />
<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<table border=\"1\" cellpadding=\"5\"><tr>\n";
foreach ($days as $day) {
	echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14%\">
	      <strong>$day</strong></td>\n";
}

for ($count=0; $count < (6*7); $count++) {
	$dayArray = getdate($start);
	if (($count % 7) == 0) {
		if ($dayArray["mon"] != $month) {
			break;
		} else {
			echo "</tr><tr>\n";
		}
	}
	if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) {
		echo "<td> </td>\n";
	} else {
		$chkEvent_sql = "SELECT event_title FROM calendar_events WHERE month(event_start) = '".$month."' AND dayofmonth(event_start) = '".$dayArray["mday"]."' AND year(event_start) = '".$year."' ORDER BY event_start";
		$chkEvent_res = mysql_query($chkEvent_sql) or die(mysql_error());

		if (mysql_num_rows($chkEvent_res) > 0) {
			$event_title = "<br/>";
			while ($ev = mysql_fetch_array($chkEvent_res)) {
				$event_title .= stripslashes($ev["event_title"])."<br/>";
			}
			mysql_free_result($chkEvent_res);
		} else {
			$event_title = "";
		}

		echo "<td valign=\"top\"><a href=event.php?m=".$month."&d=".$dayArray["mday"]."&y=$year\">".$dayArray["mday"]."</a><br/>".$event_title."</td>\n";

		unset($event_title);

		$start += ADAY;
	}
}
echo "</tr></table>";
mysql_close($mysql);
?>
</body>
</html>




This is all the code except for my, mysql db connection.

which reminds me, I would hurry up and edit your above code, You just supplied the whole internet with your sql info. So I now can very easily hack into you database and screw it up. I would definitely change your login and pass for mysql, ***IMMEDIATELY***
Was This Post Helpful? 0
  • +
  • -

#14 Eluway  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 29-June 11

Posted 01 July 2011 - 07:46 AM

Hi thanks for answering, I'm still kind of learning everything. And I did already change the username and pass. Forgot about that when I posted the code and wasn't sure how to edit the post so I just changed the info.

I tried what you suggested but it's still not working, now error connecting to the mysql which I thought was obvious since I'm calling it but not telling it where to go. So i put in a call for a php file with the login info but it's still not working right... not sure how to fix it... confused... sorry, at the tail end of a graveyard. I'll have a fresh look at it after I've gotten some sleep.

THANKS!
Was This Post Helpful? 0
  • +
  • -

#15 goyalpankaj1988  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-July 11

Posted 06 July 2011 - 12:25 PM

for ($count=0; $count < (6*7); $count++){
	$dayArray = getdate($start);
	if (($count % 7) == 0){
		if ($dayArray['mon'] != $month){
			break;
		} else {
			echo "</tr><tr>\n";
		}
	}
	if ($count < $firstDayArray['wday'] || $dayArray['mon'] != $month){
		echo "<td> </td>\n";
	} else {
		echo "<td>".$dayArray['mday']."    </td>\n";
		$start += AD



i have some problem in this section what a logic of 6*7 and what will the echo after condition true and false in both statement and hows value is come in wday in $firstdayarray
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3