954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php-calendar

hi
i design a php event calendar

but it showing some error, anyone check it plz..

Parse error: syntax error, unexpected T_ELSE in W:\www\Calendar-php\admin\calAdd.php on line 149

<html>
<head>
<title>Calendar: Add</title>


<META HTTP-EQUIV="refresh" content="1;URL=../calendar.php">
<LINK rel="stylesheet" type="text/css" name="style" href="../calendar.css">
</head>

<body bgcolor="#FFFFFF" text="#000000">



<?php


//returns highest key in the database
function getMaxKey($db) {

$maxKey = 0;

$sortby = "event_key";
$result = $db->getall();

foreach($result as $item){
           $key = $item["event_key"];
           if($key > $maxKey)
              $maxKey = $key;
}

return $maxKey;

}

// Include the FFDB library
include("../ffdb.inc.php");

//open db or create new db
$db = new FFDB();
if (!$db->open("../calendar"))
{
   // Define the database shema.
   // Note that the "last_name" field is our key.
   $schema = array(
      array("event_key", FFDB_INT, "key"),
      array("event_name", FFDB_STRING),
      array("event_description", FFDB_STRING),
      array("event_submitted_by", FFDB_STRING),
      array("event_month", FFDB_STRING),
      array("event_day", FFDB_INT),
      array("event_year", FFDB_INT)
   );

   // Try and create it...
   if (!$db->create("calendar", $schema))
   {
      echo "Error creating database\n";
      return;
   }
}

//if no key file create a new one
if(!file_exists("key.dat"))
{
 $newKey = getMaxKey($db);
 $newFile = fopen("key.dat", "w") Or die("Can't open file");
 fwrite($newFile,$newKey);
 fclose($newFile);

}

//add a record
      //convert forms to record
$fileread = fopen("key.dat", "r")Or die("Can't open file");
$data = (int) fread($fileread, 10);
fclose($fileread);
$data++;
$fileread = fopen("key.dat", "w") Or die("Can't open file");
fwrite($fileread,$data);
fclose($fileread);

//removes escape slashes
   $event = stripslashes($event);
   $description = stripslashes($description);
   $submitted = stripslashes($submitted);

//add html entities
   $event = htmlentities($event,ENT_QUOTES);
   $submitted = htmlentities($submitted,ENT_QUOTES);

   $record["event_key"] = $data;
   $record["event_name"] = $event;
   $record["event_description"] = $description;
   $record["event_submitted_by"] = $submitted;
   $record["event_month"] = $month;
   list($record["event_day"]) = sscanf($day, "%d"); // string -> int
   list($record["event_year"]) = sscanf($year, "%d"); // string -> int

      // Add a _new_ entry
      echo("");
      if (!$db->add($record))
         echo("failed!\n");
      else {



//table to display after adding
  $addedTable ="


      <center><font class=\"back\">Record Added: taking you back</font> </center>
  <table cellpadding=\"0\" cellspacing=\"2\" border=\"0\" bgcolor=\"#000000\" align=\"center\"><tr><td>
  <table cellpadding=\"3\" cellspacing=\"0\" border=\"0\" bgcolor=\"#CC0000\" align=\"center\">
<tr><td><font class=\"addHead\"><a href=\"calendar.php\" class=\"addHead\">Calendar</a></font></TD></tr>
<tr><td>

<table cellpadding=\"3\" cellspacing=\"0\" border=\"0\" bgcolor=\"#CCCCCC\">

<tr>
        <td width=\"150\" align=\"right\" height=\"26\"><font class=\"AddLeft\">Event : </font></td>
        <td width=\"350\" height=\"26\"><font class=\"AddRight\">$event</font></td>
</tr>

<tr bgcolor=\"#E3E3E3\">
    <td width=\"150\" align=\"right\"><font class=\"AddLeft\">Event Description : </font></td>
    <td width=\"350\"><font class=\"AddRight\">$description</font></td>
</tr>

<tr>
        <td width=\"150</h5>\" align=\"right\"><font class=\"AddLeft\">Date : </font></td>
        <td width=\"350\" ><font class=\"AddRight\">$day $month $year</font></td>
</tr>

<tr bgcolor=\"#E3E3E3\">
        <td width=\"150\" align=\"right\"><font class=\"AddLeft\">Submitted By : </font></td>
        <td width=\"350\"><font class=\"AddRight\">$submitted</font></td>
</tr>
</table>
</td><tr>
<tr><td align=\"right\"></td></tr>
</table>
</td></tr></table>

";

  echo $addedTable;
}

else 
{ 
echo ("go back and add event");
?>
</body>
</html>
rohnni
Junior Poster in Training
58 posts since Feb 2009
Reputation Points: 6
Solved Threads: 0
 

<?php


//returns highest key in the database
function getMaxKey($db) {

$maxKey = 0;

$sortby = "event_key";
$result = $db->getall();

foreach($result as $item){
$key = $item["event_key"];
if($key > $maxKey)
$maxKey = $key;
}

return $maxKey;

}

// Include the FFDB library
include("../ffdb.inc.php");

//open db or create new db
$db = new FFDB();
if (!$db->open("../calendar"))
{
// Define the database shema.
// Note that the "last_name" field is our key.
$schema = array(
array("event_key", FFDB_INT, "key"),
array("event_name", FFDB_STRING),
array("event_description", FFDB_STRING),
array("event_submitted_by", FFDB_STRING),
array("event_month", FFDB_STRING),
array("event_day", FFDB_INT),
array("event_year", FFDB_INT)
);

// Try and create it...
if (!$db->create("calendar", $schema))
{
echo "Error creating database\n";
return;
}
}

//if no key file create a new one
if(!file_exists("key.dat"))
{
$newKey = getMaxKey($db);
$newFile = fopen("key.dat", "w") Or die("Can't open file");
fwrite($newFile,$newKey);
fclose($newFile);

}

//add a record
//convert forms to record
$fileread = fopen("key.dat", "r")Or die("Can't open file");
$data = (int) fread($fileread, 10);
fclose($fileread);
$data++;
$fileread = fopen("key.dat", "w") Or die("Can't open file");
fwrite($fileread,$data);
fclose($fileread);

//removes escape slashes
$event = stripslashes($event);
$description = stripslashes($description);
$submitted = stripslashes($submitted);

//add html entities
$event = htmlentities($event,ENT_QUOTES);
$submitted = htmlentities($submitted,ENT_QUOTES);

$record["event_key"] = $data;
$record["event_name"] = $event;
$record["event_description"] = $description;
$record["event_submitted_by"] = $submitted;
$record["event_month"] = $month;
list($record["event_day"]) = sscanf($day, "%d"); // string -> int
list($record["event_year"]) = sscanf($year, "%d"); // string -> int

// Add a _new_ entry
echo("");
if (!$db->add($record))
echo("failed!\n");
else {

//table to display after adding
$addedTable ="

Record Added: taking you back

Calendar

Event :
$event
Event Description :
$description
\" align=\"right\">Date :
$day $month $year
Submitted By :
$submitted

";

echo $addedTable;
}

else
{
echo ("go back and add event");
?>

ahmksssv
Junior Poster in Training
84 posts since Feb 2009
Reputation Points: 11
Solved Threads: 7
 

i think you are using two else loops here ..
one is on line : 103
and another one is on line 149.
And you just forget to close your second else loop..
You loop structure is not good...
Concentrate on those...
And use code tags by next time....

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

yup :-)) thanks

rohnni
Junior Poster in Training
58 posts since Feb 2009
Reputation Points: 6
Solved Threads: 0
 

Notice: Undefined variable: sent_month in E:\domains\h\highweb.co.uk\user\htdocs\geeta\assignments\php\Calendar-php\calendar.php on line 431

<html>
<head>
<title>Calendar</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK rel="stylesheet" type="text/css" name="style" href="calendar.css">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<table cellpadding="0" cellspacing="2" border="0" align="center" bgcolor="#000000"><tr><td>
<table cellpadding="2" cellspacing="0" border="0" align="center" bgcolor="#CC0000">
<tr><td width="200" valign="middle">&nbsp;&nbsp</td>
    <td width="348" align="center">&nbsp;</td>
    <td width="200" align="right"><A HREF="admin/add.php" class="addEvent">Add Event&nbsp;&nbsp; </a></td>
</tr>
</table>
  </td></tr></table><BR><BR>


<?php
// Include the FFDB library
include("ffdb.inc.php");

//open db or create new db
$db = new FFDB();
if (!$db->open("calendar"))
{
   // Define the database shema.
   // Note that the "last_name" field is our key.
   $schema = array(
      array("event_key", FFDB_INT, "key"),
      array("event_name", FFDB_STRING),
      array("event_description", FFDB_STRING),
      array("event_submitted_by", FFDB_STRING),
      array("event_month", FFDB_STRING),
      array("event_day", FFDB_INT),
      array("event_year", FFDB_INT)
   );
      // Try and create it...
   if (!$db->create("calendar", $schema))
   {
      echo "Error creating database\n";
      return;
   }
}

function today($record)
{          global $event_day;
           global $event_month;
           global $event_year;

         //echo "$event_month $event_day $event_year";
   if (($record["event_month"] == $event_month) &&
           ($record["event_day"] == $event_day) &&
           ($record["event_year"] == $event_year))
          return true;
          return false;
}

function show_event($record){
         $eventNumber = $record["event_key"];
         $eventName = $record["event_name"];
         echo "<font class=\"eventLink\">-<a href=\"viewEvent.php?eventNumber=$eventNumber\" class=\"eventLink\">$eventName</a></font> ";
}

function getEvents(){
global $db;
         //get events for today
$result = $db->getbyfunction("today");

//display events if there are any
if($result != null)
foreach($result as $item)
   show_event($item);
}

function days_in_month($_month, $_year)
{

        if($_month == 2)
        {        return days_in_feb($_year);  }

        else {

        if($_month == 1 || $_month == 3 || $_month == 5 || $_month == 7 || $_month == 8 || $_month == 10 || $_month == 12)
             {        return(31);  }
        else {  return(30);  }
        }

}

function selectMonth($_month){

$selectstart = "
<select name=\"sent_month\">  ";
$selectend = "
</select>";

echo $selectstart;

echo "<option value=\"January\"";
       if($_month == 1)
          echo " selected=\"selected\" ";
echo ">January</option>
";

echo "<option value=\"February\"";
       if($_month == 2)
          echo " selected=\"selected\" ";
echo ">February</option>
";

echo "<option value=\"March\"";
       if($_month == 3)
          echo " selected=\"selected\" ";
echo ">March</option>
";

echo "<option value=\"April\"";
       if($_month == 4)
          echo " selected=\"selected\" ";
echo ">April</option>
";

echo "<option value=\"May\"";
       if($_month == 5)
          echo " selected=\"selected\" ";
echo ">May</option>
";

echo "<option value=\"June\"";
       if($_month == 6)
          echo " selected=\"selected\" ";
echo ">June</option>
";

echo "<option value=\"July\"";
       if($_month == 7)
          echo " selected=\"selected\" ";
echo ">July</option>
";

echo "<option value=\"August\"";
       if($_month == 8)
          echo " selected=\"selected\" ";
echo ">August</option>
";

echo "<option value=\"September\"";
       if($_month == 9)
          echo " selected=\"selected\" ";
echo ">September</option>
";

echo "<option value=\"October\"";
       if($_month == 10)
          echo " selected=\"selected\" ";
echo ">October</option>
";

echo "<option value=\"November\"";
       if($_month == 11)
          echo " selected=\"selected\" ";
echo ">November</option>
";

echo "<option value=\"December\"";
       if($_month == 12)
          echo " selected=\"selected\" ";
echo ">December</option>
";


echo $selectend;

}

function selectYear($selectedyear){
      $day = getdate();
      $year = $day['year'];


$selectyeartop = "

<select name=\"sent_year\">
";
$selectyearbottom = "
</select>
";
         echo $selectyeartop;

         for($i=$year; $i<$year+5; $i++) {
             echo "<option value=\"$i\"";
             if($i == $selectedyear)
                echo "selected=\"selected\"";
             echo "> $i</option>
             ";

         }

         echo $selectyearbottom;

}

function convertMonth($alpha_month){
         if($alpha_month == "January")
              return 1;
         else if($alpha_month== "February")
              return 2;
         else if($alpha_month== "February")
              return 2;
         else if($alpha_month== "March")
              return 3;
         else if($alpha_month== "April")
              return 4;
         else if($alpha_month== "May")
              return 5;
         else if($alpha_month== "June")
              return 6;
         else if($alpha_month== "July")
              return 7;
         else if($alpha_month== "August")
              return 8;
         else if($alpha_month== "September")
              return 9;
         else if($alpha_month== "October")
              return 10;
         else if($alpha_month== "November")
              return 11;
         else if($alpha_month== "December")
              return 12;

         return 1;

}


function days_in_feb($year){

        //$year must be YYYY
        //[gregorian] leap year math :

        if ($year < 0) $year++;
        $year += 4800;

    if ( ($year % 4) == 0) {
                if (($year % 100) == 0) {
                    if (($year % 400) == 0) {
                                return(29);
                    } else {
                                return(28);
                    }
                } else {
                    return(29);
                }
    } else {
                return(28);
    }
}


/*
  prints the month and year that are passed to it in
  $date
*/
function printMonth($_month, $_year)
{

$timestamp = mktime(0,0,0,$_month,1,2000);
$date = getdate ($timestamp);
$monthText = $date['month'];


 $monthtext1 =
"
<!-- month heading -------------------------------------------->
<table align=\"center\">
<tr>
<td align=\"left\">
 <form name=\"goto\" action=\"calendar.php\" method=\"POST\">
<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" bgcolor=\"#000000\" align=\"center\">
<tr><td>
<table cellpadding=\"5\" cellspacing=\"0\" border=\"0\" bgcolor=\"#CC0000\">
<tr><td width=\"200\">";

$monthtext2 = "<input type=\"image\" src=\"go.gif\" name=\"go\" border=\"0\">

</td></tr></table>
</td></tr></table>
</form>
</td>

<td align=\"center\" width=\"355\" valign=\"top\"><font class=\"month\">$monthText $_year</font></td>
<td align=\"right\" width=\"186\" valign=\"top\"></td>
</tr>
</table>
<!-- end of month heading ------------------------------------->

";
 echo "$monthtext1";
 selectMonth($_month);
 selectYear($_year);
 echo "$monthtext2";
}

/*
  prints the bar that contains the days of the week
*/
function printDays()
{
 $daybar =
"
<!-- days of the week heading --------------------------------->
<table align=\"center\" bgcolor=\"#000000\">
<TR>
<td width=\"105\" align=\"center\" bgcolor=\"#CC0000\"><font class=\"daysfont\">Sunday</font></td>
<td width=\"105\" align=\"center\" bgcolor=\"#CC0000\"><font class=\"daysfont\">Monday</font></td>
<td width=\"105\" align=\"center\" bgcolor=\"#CC0000\"><font class=\"daysfont\">Tuesday</font></td>
<td width=\"105\" align=\"center\" bgcolor=\"#CC0000\"><font class=\"daysfont\">Wednesday</font></td>
<td width=\"105\" align=\"center\" bgcolor=\"#CC0000\"><font class=\"daysfont\">Thursday</font></td>
<td width=\"105\" align=\"center\" bgcolor=\"#CC0000\"><font class=\"daysfont\">Friday</font></td>
<td width=\"105\" align=\"center\" bgcolor=\"#CC0000\"><font class=\"daysfont\">Saturday</font></td>
</tr>

<!-- end days of the week heading ----------------------------->

";

  echo $daybar;
}


/*
  opens table for calendar which is closed by last week, then prints the first
  week to the calendar
*/
function printFirstWeek($_day)
{
 global $event_day;
//write table declarations
 echo "

<!-- begin day boxes ------------------------------------------>


<tr>

 ";

 $current_day = 1;

 $spot = 0;

 while ($spot < $_day){

        echo "<td width=\"105\" height=\"115\" valign=\"top\" bgcolor=\"#e3e3e3\">&nbsp</td>
        ";
        $spot++;
 }

 while ($spot < 7){
        $event_day = $current_day;
        echo "<td width=\"105\" height=\"115\" valign=\"top\" bgcolor=\"#CCCCCC\"><font class=\"number\">$current_day</font>";
        getEvents();
        echo "</td>
        ";

        $spot++;
        $current_day++;

 }

echo"</tr>
";

return $current_day;
}

function printWeek($_day, $_last)
{
 global $event_day;

 while ($_day <= ($_last - 7)){
    $count = 0;
    echo "<TR>
    ";
    while($count < 7){
          $event_day = $_day;
          echo "<td width=\"105\" height=\"115\" valign=\"top\" bgcolor=\"#CCCCCC\"><font class=\"number\">$_day</font>";
          getEvents();
          echo "</td>
          ";
          $_day++;
          $count++;
    }
    echo "</TR>
    ";
 }
    return $_day;

}

function printLastWeek($_day, $_lastday)
{
        global $event_day;
 $count = 0;
      echo "<TR>
    ";
 while($count <= $_lastday)
 {
           $event_day = $_day;
           echo "<td width=\"105\" height=\"115\" valign=\"top\" bgcolor=\"#CCCCCC\"><font class=\"number\">$_day</font>";
           getEvents();
           echo "</td>
          ";
          $_day++;
          $count++;
 }

 while($count < 7)
 {
         echo "<td width=\"105\" height=\"115\" valign=\"top\" bgcolor=\"#e3e3e3\">&nbsp;</td>
        ";
        $count++;
        $_day++;
 }

 echo "</tr>
 ";
 echo "</table>
 <!-- end day boxes ------------------------------------------>

 ";
 }



//calculate all date information needed
if($sent_month && $sent_year){
   $month = convertMonth($sent_month);
   $year = $sent_year;
   $event_day = 1;
   $event_month = $sent_month;
   $event_year = $year;
   }
else {
      $day = getdate();
      $month = $month = $day['mon'];
      $mday = $mday = $day['mday'];
      $year = $year = $day['year'];
      $event_day = 1;
      $event_month = $day['month'];
      $event_year = $year;
      }


$days_in_month = days_in_month ($month, $year);

$first_day = mktime(0,0,0,$month,1,$year);
$date_first = getdate ($first_day);

$last_day = mktime(0,0,0,$month,$days_in_month,$year);
$date_last = getdate($last_day);

$dayofweekfirst = $date_first['wday'];
$dayofweeklast = $date_last['wday'];
//end date calculations





printMonth($month, $year);
printDays();
$current = printFirstWeek($dayofweekfirst);
$current = printWeek($current, $days_in_month);
printLastWeek($current, $dayofweeklast);



?>

<table cellpadding="0" cellspacing="0" border="0" align="center"><TR><TD width="750"><A href="viewAll.php" class="viewEvent">View All Events</a></td></tr></table>
<table cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td width="600" align="center">&nbsp;</td>
</tr>
</table>
</BODY>
</HTML>
rohnni
Junior Poster in Training
58 posts since Feb 2009
Reputation Points: 6
Solved Threads: 0
 

Notice: Undefined variable: event in E:\domains\h\highweb.co.uk\user\htdocs\geeta\assignments\php\Calendar-php\admin\calAdd.php on line 46

Notice: Undefined variable: description in E:\domains\h\highweb.co.uk\user\htdocs\geeta\assignments\php\Calendar-php\admin\calAdd.php on line 47

Notice: Undefined variable: submitted in E:\domains\h\highweb.co.uk\user\htdocs\geeta\assignments\php\Calendar-php\admin\calAdd.php on line 48

Notice: Undefined variable: month in E:\domains\h\highweb.co.uk\user\htdocs\geeta\assignments\php\Calendar-php\admin\calAdd.php on line 55

Notice: Undefined variable: day in E:\domains\h\highweb.co.uk\user\htdocs\geeta\assignments\php\Calendar-php\admin\calAdd.php on line 56

Notice: Undefined variable: year in E:\domains\h\highweb.co.uk\user\htdocs\geeta\assignments\php\Calendar-php\admin\calAdd.php on line 57

Fatal error: Invalid string value field during add: event_month in E:\domains\h\highweb.co.uk\user\htdocs\geeta\assignments\php\Calendar-php\ffdb.inc.php on line 487

Attachments code.txt (96.9KB)
rohnni
Junior Poster in Training
58 posts since Feb 2009
Reputation Points: 6
Solved Threads: 0
 

you are not initialised or used these variables $sent_month and $sent_year before...what data you want to put in that variable...
refine your code and write coding accordingly....

use code tags....

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

hii
i m designing a php event based calendar
this is my code, can anyone tell me its script code,mine is not working..

<!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=iso-8859-1" />
<title>Untitled Document</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
// Get values from query string 
$day = $_GET["day"]; 
$month = $_GET["month"]; 
$year = $_GET["year"]; 
$sel = $_GET["sel"]; 
$what = $_GET["what"]; 

if($day == "") 
$day = date("j"); 

if($month == "") 
$month = date("m"); 

if($year == "") 
$year = date("Y"); 
$currentTimeStamp = strtotime("$year-$month-$day"); 
$monthName = date("F", $currentTimeStamp); 
$numDays = date("t", $currentTimeStamp); 
$counter = 0; 
$numEventsThisMonth = 0; 
$hasEvent = false; 
$todaysEvents = ""; 

<table width='350' border='0' cellspacing='0' cellpadding='0'> 
<tr> 
<td class='head' width='50'>S</td> 
<td class='head' width='50'>M</td> 
<td class='head' width='50'>T</td> 
<td class='head' width='50'>W</td> 
<td class='head' width='50'>T</td> 
<td class='head' width='50'>F</td> 
<td class='head' width='50'>S</td> 
</tr> 

$numDays = date("t", $currentTimeStamp); 
for($i = 1; $i < $numDays+1; $i++, $counter++) 
{ 
$timeStamp = strtotime("$year-$month-$i"); 

if($i == 1) 
{ 
// Workout when the first day of the month is 
$firstDay = date("w", $timeStamp); 

for($j = 0; $j < $firstDay; $j++, $counter++) 
echo "<td>&nbsp;</td>"; 
} 

if($counter % 7 == 0) 
echo "</tr><tr>"; 

echo "<td width='50'>$I</td>"; 

if(date("w", $timeStamp) == 0 || date("w", $timeStamp) == 6) 
echo "class='weekend'"; 
else 
if($i == date("d") && $month == date("m") && $year == date("Y")) 
echo "class='today'"; 
else 
echo "class='normal'"; 
$monthName = date("F", $currentTimeStamp); 

<tr> 
<td width='50' colspan='1'> 
<input type='button' value=' < ' onClick='goLastMonth(<?php echo $month . ", " . $year; ?>)'> 
</td> 
<td width='250' colspan='5'> 
<span class='title'><?php echo $monthName . " " . $year; ?></span> 
</td> 
<td width='50' colspan='1' align='right'> 
<input type='button' value=' > ' onClick='goNextMonth(<?php echo $month . ", " . $year; ?>)'> 
</td> 
</tr> 

<script>
function goLastMonth(month, year) 
{ 
// If the month is Januaru, decrement the year 
if(month == 1) 
{ 
--year; 
month = 13; 
} 

document.location.href = 'cal.php?month='+(month-1)+'&year='+year; 
} 
cal.php?month=12&year=2002 
function goNextMonth(month, year) 
{ 
// If the month is December, increment the year 
if(month == 12) 
{ 
++year; 
month = 0; 
} 

document.location.href = 'cal.php?month='+(month+1)+'&year='+year; 
} 


</script>
<?php
function ReadEvents($Month) 
function ReadEvents($Month) 
{ 

$theEvents = array(); 
$eventCounter = 0; 

// Make sure that the file exists 
if(!file_exists($_SERVER["DOCUMENT_ROOT"] . "/" . EVENT_FILE)) 
{ 
$fp = @fopen($_SERVER["DOCUMENT_ROOT"] . "/" . EVENT_FILE, "w") 
or die("<span class='error'>ERROR: Couldn't create events file.</span>"); 
@fclose($fp); 
} 
$fp = @fopen($_SERVER["DOCUMENT_ROOT"] . "/" . EVENT_FILE, "rb") 
or die("<span class='error'>ERROR: Couldn't open events file to read events.</span>"); 
define("EVENT_FILE", "cal_events.text"); 
while($data = fread($fp, 1024)) 
{ 
$events .= $data; 
} 

@fclose($fp); 
// Seperate the data into line-seperated arrays 
$arrEvents = explode("\r\n", $events); 
// Loop through the results and pick the arrays 
// that match the selected month 
for($i = 0; $i < sizeof($arrEvents); $i+=3) 
{ 
// Get each part of the events date as an index 
// of an array 
$arrEventDate = explode(" ", $arrEvents[$i]); 

// If the month is the selected month the grab 
// the details of this event 
if((int)$arrEventDate[0] == (int)$Month) 
{ 
$theEvents[$eventCounter++] = array("day" => $arrEventDate[1], "name" => $arrEvents[$i+1], "desc" => $arrEvents[$i+2]); 
} 
} 



return $theEvents; 
foreach($arrEvents as $eventEntry) 
{ 
if($eventEntry["day"] == $i) 
{ 
// We have at least one event for the day 
$hasEvent = true; 
$numEventsThisMonth++; 
… 
} 
} 
} 

// Is it a weekend, does it have events, etc 
if($i == $day && $month == date("m") && $year == date("Y") && $sel == 1) 
echo "class='selected'"; 
else if($i == $day && $sel == 1) 
echo "class='selected'"; 
else if($hasEvent == true) 
echo "class='event'"; 
else 
if(date("w", $timeStamp) == 0 || date("w", $timeStamp) == 6) 
echo "class='weekend'"; 
else 
if($i == date("d") && $month == date("m") && $year == date("Y")) 
echo "class='today'"; 
else 
echo "class='normal'"; 

$arrEvents = ReadEvents($month); 

... 

foreach($arrEvents as $eventEntry) 
{ 
if($eventEntry["day"] == $i) 
{ 
// We have at least one event for the day 
$hasEvent = true; 
$numEventsThisMonth++; 

if($eventEntry["day"] == $day) 
{ 
// Add the event to the $todaysEvents variable 
$todaysEvents .= "<span class='eventTitle'>" . stripslashes($eventEntry["name"]) . "</span>"; 

$todaysEvents .= "<span class='eventDesc'>" . stripslashes($eventEntry["desc"]) . "</span>"; 

$todaysEvents .= " <a href='cal.php?sel=1&what=delPost&day=$day&month=$month&year=$year&eName=" . urlencode($eventEntry["name"]) . "&eDesc=" . urlencode($eventEntry["desc"]) . "'>[Remove]</a>"; 
} 
} 
} 



if($sel == 1) 
{ 
echo "<tr>"; 
echo " <td width='350' colspan='7'>"; 
echo " <hr size='1' color='#CACACA' noshade>"; 
echo " <span class='Title'>Today's Events</span>"; 
echo $todaysEvents; 
echo " </td>"; 
echo "</tr>"; 
} 


?>

</body>
</html>


Parse error: syntax error, unexpected '<' in W:\www\ccc\cal.php on line 34

rohnni
Junior Poster in Training
58 posts since Feb 2009
Reputation Points: 6
Solved Threads: 0
 


<?php
// Get values from query string
$day = $_GET["day"];
$month = $_GET["month"];
$year = $_GET["year"];
$sel = $_GET["sel"];
$what = $_GET["what"];

if($day == "")
$day = date("j");

if($month == "")
$month = date("m");

if($year == "")
$year = date("Y");
$currentTimeStamp = strtotime("$year-$month-$day");
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
$numEventsThisMonth = 0;
$hasEvent = false;
$todaysEvents = "";

S
M
T
W
T
F
S

$numDays = date("t", $currentTimeStamp);
for($i = 1; $i < $numDays+1; $i++, $counter++)
{
$timeStamp = strtotime("$year-$month-$i");

if($i == 1)
{
// Workout when the first day of the month is
$firstDay = date("w", $timeStamp);

for($j = 0; $j < $firstDay; $j++, $counter++)
echo " ";
}

if($counter % 7 == 0)
echo "";

echo "$I";

if(date("w", $timeStamp) == 0 || date("w", $timeStamp) == 6)
echo "class='weekend'";
else
if($i == date("d") && $month == date("m") && $year == date("Y"))
echo "class='today'";
else
echo "class='normal'";
$monthName = date("F", $currentTimeStamp);




<?php echo $monthName . " " . $year; ?>




<?php
function ReadEvents($Month)
function ReadEvents($Month)
{

$theEvents = array();
$eventCounter = 0;

// Make sure that the file exists
if(!file_exists($_SERVER["DOCUMENT_ROOT"] . "/" . EVENT_FILE))
{
$fp = @fopen($_SERVER["DOCUMENT_ROOT"] . "/" . EVENT_FILE, "w")
or die("ERROR: Couldn't create events file.");
@fclose($fp);
}
$fp = @fopen($_SERVER["DOCUMENT_ROOT"] . "/" . EVENT_FILE, "rb")
or die("ERROR: Couldn't open events file to read events.");
define("EVENT_FILE", "cal_events.text");
while($data = fread($fp, 1024))
{
$events .= $data;
}

@fclose($fp);
// Seperate the data into line-seperated arrays
$arrEvents = explode("\r\n", $events);
// Loop through the results and pick the arrays
// that match the selected month
for($i = 0; $i < sizeof($arrEvents); $i+=3)
{
// Get each part of the events date as an index
// of an array
$arrEventDate = explode(" ", $arrEvents[$i]);

// If the month is the selected month the grab
// the details of this event
if((int)$arrEventDate[0] == (int)$Month)
{
$theEvents[$eventCounter++] = array("day" => $arrEventDate[1], "name" => $arrEvents[$i+1], "desc" => $arrEvents[$i+2]);
}
}

return $theEvents;
foreach($arrEvents as $eventEntry)
{
if($eventEntry["day"] == $i)
{
// We have at least one event for the day
$hasEvent = true;
$numEventsThisMonth++;

}
}
}

// Is it a weekend, does it have events, etc
if($i == $day && $month == date("m") && $year == date("Y") && $sel == 1)
echo "class='selected'";
else if($i == $day && $sel == 1)
echo "class='selected'";
else if($hasEvent == true)
echo "class='event'";
else
if(date("w", $timeStamp) == 0 || date("w", $timeStamp) == 6)
echo "class='weekend'";
else
if($i == date("d") && $month == date("m") && $year == date("Y"))
echo "class='today'";
else
echo "class='normal'";

$arrEvents = ReadEvents($month);

...

foreach($arrEvents as $eventEntry)
{
if($eventEntry["day"] == $i)
{
// We have at least one event for the day
$hasEvent = true;
$numEventsThisMonth++;

if($eventEntry["day"] == $day)
{
// Add the event to the $todaysEvents variable
$todaysEvents .= "" . stripslashes($eventEntry["name"]) . "";

$todaysEvents .= "
" . stripslashes($eventEntry["desc"]) . "
";

$todaysEvents .= " [Remove]

";
}
}
}

if($sel == 1)
{
echo "";
echo " ";
echo " ";
echo " Today's Events

";
echo $todaysEvents;
echo " ";
echo "";
}


?>

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

wat u mean?

rohnni
Junior Poster in Training
58 posts since Feb 2009
Reputation Points: 6
Solved Threads: 0
 

:) Nevermind! To decipher that 'string', you should atleast be in 3rd grade.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 
<html>
<head>
<title>Calendar: Add</title>
<META HTTP-EQUIV="refresh" content="1;URL=../../calendar.php">
<LINK rel="stylesheet" type="text/css" name="style" href="../../calendar.css">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php

function getMaxKey($db)
{
    $maxKey = 0;
    $sortby = "event_key";
    $result = $db->getall();
    foreach ($result as $item) {
        $key = $item["event_key"];
        if ($key > $maxKey) $maxKey = $key;
    }
    return $maxKey;
}
include ("../../ffdb.inc.php");
$db = new FFDB();
if (!$db->open("../calendar")) {
    $schema = array(array("event_key", FFDB_INT, "key"), array("event_name",
        FFDB_STRING), array("event_description", FFDB_STRING), array("event_submitted_by",
        FFDB_STRING), array("event_month", FFDB_STRING), array("event_day", FFDB_INT),
        array("event_year", FFDB_INT));
    if (!$db->create("calendar", $schema)) {
        echo "Error creating database\n";
        return;
    }
}
if (!file_exists("key.dat")) {
    $newKey = getMaxKey($db);
    $newFile = fopen("key.dat", "w") or die("Can't open file");
    fwrite($newFile, $newKey);
    fclose($newFile);
}
else {
	$fileread = fopen("key.dat", "r") or die("Can't open file");
	$data = (int)fread($fileread, 10);
	fclose($fileread);
	$data++;
	$fileread = fopen("key.dat", "w") or die("Can't open file");
	fwrite($fileread, $data);
	fclose($fileread);
}
$event = stripslashes($event);
$description = stripslashes($description);
$submitted = stripslashes($submitted);
$event = htmlentities($event, ENT_QUOTES);
$submitted = htmlentities($submitted, ENT_QUOTES);
$record["event_key"] = $data;
$record["event_name"] = $event;
$record["event_description"] = $description;
$record["event_submitted_by"] = $submitted;
$record["event_month"] = $month;
list($record["event_day"]) = sscanf($day, "%d");
list($record["event_year"]) = sscanf($year, "%d");
echo ("");
{
    echo $addedTable;

else 
{
    echo ("go back and add event");
}
}
?>
</body>
</html>


Parse error: syntax error, unexpected T_ELSE in E:\domains\h\highweb.co.uk\user\htdocs\geeta\assignments\php\calendar\admin\calAdd.php on line 64

rohnni
Junior Poster in Training
58 posts since Feb 2009
Reputation Points: 6
Solved Threads: 0
 

Whats wrong with you???
Use Code Tags...

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 
Whats wrong with you??? Use Code Tags...


how to use code tags?

rohnni
Junior Poster in Training
58 posts since Feb 2009
Reputation Points: 6
Solved Threads: 0
 
<html>
<head>
<title>Calendar: Add</title>
<META HTTP-EQUIV="refresh" content="1;URL=../../calendar.php">
<LINK rel="stylesheet" type="text/css" name="style" href="../../calendar.css">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php

function getMaxKey($db)
{
    $maxKey = 0;
    $sortby = "event_key";
    $result = $db->getall();
    foreach ($result as $item) {
        $key = $item["event_key"];
        if ($key > $maxKey) $maxKey = $key;
    }
    return $maxKey;
}
include ("../../ffdb.inc.php");
$db = new FFDB();
if (!$db->open("../calendar")) {
    $schema = array(array("event_key", FFDB_INT, "key"), array("event_name",
        FFDB_STRING), array("event_description", FFDB_STRING), array("event_submitted_by",
        FFDB_STRING), array("event_month", FFDB_STRING), array("event_day", FFDB_INT),
        array("event_year", FFDB_INT));
    if (!$db->create("calendar", $schema)) {
        echo "Error creating database\n";
        return;
    }
}
if (!file_exists("key.dat")) {
    $newKey = getMaxKey($db);
    $newFile = fopen("key.dat", "w") or die("Can't open file");
    fwrite($newFile, $newKey);
    fclose($newFile);
}
else {
	$fileread = fopen("key.dat", "r") or die("Can't open file");
	$data = (int)fread($fileread, 10);
	fclose($fileread);
	$data++;
	$fileread = fopen("key.dat", "w") or die("Can't open file");
	fwrite($fileread, $data);
	fclose($fileread);
}
$event = stripslashes($event);
$description = stripslashes($description);
$submitted = stripslashes($submitted);
$event = htmlentities($event, ENT_QUOTES);
$submitted = htmlentities($submitted, ENT_QUOTES);
$record["event_key"] = $data;
$record["event_name"] = $event;
$record["event_description"] = $description;
$record["event_submitted_by"] = $submitted;
$record["event_month"] = $month;
list($record["event_day"]) = sscanf($day, "%d");
list($record["event_year"]) = sscanf($year, "%d");
echo ("");
{
    echo $addedTable;

else 
{
    echo ("go back and add event");
}
}
?>
</body>
</html>

Parse error: syntax error, unexpected T_ELSE in E:\domains\h\highweb.co.uk\user\htdocs\geeta\assignments\php\calendar\admin\calAdd.php on line 64

Hi....
The below code having one wrong if condition....u need to open on if conition ....u can not open{ for echo....

<strong>echo ("");
{</strong>
    echo $addedTable;

else 
{
    echo ("go back and add event");
}
ahmksssv
Junior Poster in Training
84 posts since Feb 2009
Reputation Points: 11
Solved Threads: 7
 
how to use code tags?


As you been already instructed in PM's that you so blatantly ignored[code]YOUR CODE HERE[/code]
OR
[code=php]YOUR CODE HERE[/code]
where php can be replaced by name of any programming language as necessary.

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You