Availability Calendar PHP Error Message

Availability Calendar PHP Error Message

Postby dewhickey » Wed Jan 14, 2009 6:15 pm

I think this calendar is exactly what I've spent dozens of hours searching for. You're right, everything else out there is too simple or too complex. This one's just right. But I'm having a problem getting it to run. I've properly changed the settings in db_connect.inc.php and uploaded all the files to the server. The table was successfully created in my database using db_table_create.php (checked it using phpMyAdmin).

When I run index.php in Firefox, I get the following error:

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /home2/dewhicke/public_html/bayviewnetwork/availability/functions.inc.php on line 69

This is the code in functions.inc.php that seem to be causing the trouble, beginning on line 69:

68. // check if day is available
69. if(array_key_exists($this_date,$booked_days)){
70. //echo "<br>".$booked_days[$this_date];
71. if($booked_days[$this_date]=="am") $day_image='cal_am_'.$day_counter.'.png';
72. elseif($booked_days[$this_date]=="pm") $day_image='cal_pm_'.$day_counter.'.png';
73. else $day_image='cal_on_'.$day_counter.'.png';
74. }

This message displays over and over and over again -- something like 300 times.

Then. at the bottom of this repeating error, the Availability Calendar finally appears. It looks great, but when I select a date, I get another error:

ERROR INSERTING. INSERT INTO bookings_cal SET id_item='2', the_date='2009-08-07', state=''

I'm hoping somebody can tell me what's going on here.
I would really like to be able to use this terrific calendar.

Thanks
dewhickey
 
Posts: 15
Joined: Tue Jan 13, 2009 4:38 pm

Re: Availability Calendar PHP Error Message

Postby chris » Wed Jan 14, 2009 7:09 pm

Hi there and welcome to the forum

Whoops, you have just fond a bug in the new zipped version that I uploaded a few days ago (see this post)
Basically I moved the mysql call to check dates into the function but "forgot" to define the $booked_days var as an array before checking each month.

You need to add this line:
Code: Select all
$booked_days=array();

right before the code queries the db fr booked dates - ie line 14

I will fix the zipped version right now.
Sorry about that :(

AS to the insert error... I ma not sure why you are getting that. The calendar is updated in the ajax file so you shouldn't be getting any update errrors in the code....
Once you have fixed the first problem. let me know if this second one still occurs and, if possible, pm me an url so that I can try to work out what is happening.

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Availability Calendar PHP Error Message

Postby dewhickey » Wed Jan 14, 2009 7:55 pm

Wow, thanks for the prompt reply. I put in the code that assigns the array just before it's used on line 69 just before it's called. When I ran it in Firefox, the repeating error I was getting was no longer there. Big smile. The calendar appears properly. Unfortunately, when I click on any date, I still get a pop-up error:

"The page at http://www.bayviewnetwork.net says:"
ERROR INSERTING. INSERT INTO bookings_cal SET id_item='2', the_date='2009-04-17', state=''

There might be more info at the end of the message, but it doesn't display beyond that point.

When I close the pop-up error message, the number of the day I had selected is gone. In its place is the little circular arrows animation. These animations continue to display in any dates that I attempt to select.

If you want to look at it, here's the URL:

bayviewnetwork.net/availability

Hay, thanks for your help.
Pete
dewhickey
 
Posts: 15
Joined: Tue Jan 13, 2009 4:38 pm

Re: Availability Calendar PHP Error Message

Postby chris » Wed Jan 14, 2009 8:11 pm

OK, glad error one is fixed.

The alert error you are getting is coming from the ajax file that is apparantely unable to insert the newly booked date.
So something is wrong in there.
In the update_cal.ajax.php file can you add a mysql_error() output to the line that is returning the error.

Change this line (44):
Code: Select all
if(!mysql_query($insert))   die("ERROR INSERTING. ".$insert."");

to this:
Code: Select all
if(!mysql_query($insert))   die("ERROR INSERTING. ".$insert."<br>".mysql_error());


When you then reload the calendar and click on a date, the message should also tell you more details as to why the mysql insert hasn't worked.
Let me know when you have done that so that I can see it.
It looks like that for some reason it isn't connecting to the database - have you moved the db_connect file or are using another file?

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Availability Calendar PHP Error Message

Postby dewhickey » Wed Jan 14, 2009 8:46 pm

I made the change and now the error message is this:

ERROR INSERTING. INSERT INTO bookings_cal SET id_item='2', the_date='2009-05-15', state=''<br>Unknown column 'state' in 'field list'

As to the db_connect file, all I did was change the values for id, password, and database name. I did not move the file from it's original location.

Pete
dewhickey
 
Posts: 15
Joined: Tue Jan 13, 2009 4:38 pm

Re: Availability Calendar PHP Error Message

Postby chris » Wed Jan 14, 2009 8:58 pm

oh, dear, I really have messed something up with this last zip file :(
The db_create sql code is missing the line for the "state" column (used for am and pm states)

If you have direct db access via phpMyAdmin you need to run this sql query:

Code: Select all
ALTER TABLE `bookings_cal` ADD `state` CHAR( 3 ) NOT NULL DEFAULT 'all'


Alternatively you can do this via the php by adding this code to the index.php file ((make sure it is AFTER the db connection) and load the file in your browser:
Code: Select all
$sql="ALTER TABLE `".T_BOOKINGS."` ADD `state` CHAR( 3 ) NOT NULL DEFAULT 'all' ";
mysql_query($sql) or die("error altering table");


Sorry about this.... (off to modify the zipped version again :( )

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Availability Calendar PHP Error Message

Postby chris » Wed Jan 14, 2009 9:15 pm

put the query I posted in line 40 more or less - ie AFTER the calendar table has been defined.
Chris

PS. remove this bit of code once the new table field has been created.
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Availability Calendar PHP Error Message

Postby dewhickey » Wed Jan 14, 2009 9:17 pm

I have access to phpMyAdmin, but I don't know how to run the query. I clicked on query and pasted the script into the submit query box, but I get back a message: "You have to choose at least one column to display."

So, I added the other script to index.php just below the line, $file = "db_connect.inc.php"; (line 13)

When I run the calendar again in Firefox, I get this:

Warning: mysql_query() [function.mysql-query]: Access denied for user 'dewhicke'@'localhost' (using password: NO) in /home2/dewhicke/public_html/bayviewnetwork/availability/index.php on line 14

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home2/dewhicke/public_html/bayviewnetwork/availability/index.php on line 14
error altering table

If I put the script down a few lines, on line 15, I just get a simple message:

"error altering table"

Sorry about all the hassle

Pete
dewhickey
 
Posts: 15
Joined: Tue Jan 13, 2009 4:38 pm

Re: Availability Calendar PHP Error Message

Postby dewhickey » Wed Jan 14, 2009 9:23 pm

Yes, Yes, Yes, It seems to be working now. You are good.

Now I can start playing with it. Looking forward to changing to three month display. I see there is lots of info on this in the forum.

And I think I saw an entry in the forum for setting up the front end display for people to view.

Do you think I should re-download the zip file and start over?

Thanks a lot. I've been pulling my hair out for weeks looking for a script like this. I must have looked at a hundred websites after running every kind of query I could think of in Yahoo and Google.

Thanks again.

Pete
dewhickey
 
Posts: 15
Joined: Tue Jan 13, 2009 4:38 pm

Re: Availability Calendar PHP Error Message

Postby chris » Wed Jan 14, 2009 9:29 pm

Excellent, I am glad you got it working!

No need to download again, you now have the same (ie I have made the changes that we have discussed here)

I've been pulling my hair out for weeks looking for a script like this. I must have looked at a hundred websites after running every kind of query I could think of in Yahoo and Google

funny - searching for "php availability calendar" in google shows my script 6th in the results - I suppose it just depends on the search terms :)

A lot of modifications and adaptions have been discussed on this forum over the last year, I am quite (plesently) surprised by the response. It is shame the work commitments have meant that I haven't been able to roll out all the improvements in a new version.

Anyway, have fun using it :)

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Next

Return to General

Who is online

Users browsing this forum: No registered users and 0 guests

cron