Forum Moderators: coopster

Message Too Old, No Replies

PHP events calender

the events file is not being created

         

Pozo

7:48 pm on Feb 23, 2010 (gmt 0)

10+ Year Member



I am trying to make an events calender with PHP. Although the calender seems to be working fine, all the months and dates etc, but the following error is displayed:

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."); >?

I have the following line of code right in the beginning of my code

echo define("EVENT_FILE", "cal_events.text");

and to read events of a month, i have the following code which obviously doesnt work cause the file has not been created

function ReadEvents($Month)
{

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


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>");

As I am only a beginner, I am sure there is something wrong with the code. Can someone please identify?

Anyango

7:52 pm on Feb 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



echo define("EVENT_FILE", "cal_events.text");

remove the echo from there and try again

Pozo

2:33 pm on Feb 24, 2010 (gmt 0)

10+ Year Member



O o
I think I have made some serious error in my code. :(
When i removed echo, even the calendar disappeared.
What to do?

penders

2:52 pm on Feb 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Removing the 'echo' from that line (obviously still keeping the define() statement) should make no difference!? All that will do is echo/print "1" or "" (ie. nothing) to your page, since the define() statement returns a boolean.

You are unlikely to have perms to create a file in your DOCUMENT_ROOT, which is probably why it is failing. Try removing the '@' from the beginning of your fopen() call to get a more meaningful error message. Not sure why your error message appears to include your actual PHP code - unless a closing quote was missing?!

Matthew1980

2:59 pm on Feb 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HI there Pozo,

Could just be a typo, exactly like penders mentioned:-


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."); >?


They are the wrong way around! Try altering that, still leave the echo off the define too, should be good then. Either that or I have misread the original error and it was meant to be like that. lol!

Cheers,

MRb

EDIT: Shouldn't the file format be .txt & not .text ?