By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,930 Members | 633 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,930 IT Pros & Developers. It's quick & easy.

Help with Calender and adding an event

nomad
Expert 100+
P: 664
Hello Everyone:

I'm having troubles with some coding and Idon't know where it is. I have delevopled a calender where the client can add events to a day. The code worked perfect on my computer but when I transfer the info I get this error.

The server encountered an unexpected condition which prevented it from fulfilling the request.
The script had an error or it did not produce any output. If there was an error, you should be able to see it in the error log.

Note there is not error code at the bottom of the page.

Here is my code for the Calender.
[PHP]
<?php
$conn = mysql_connect("localhost", "nomad1", "nomad1") or die(mysql_error());
mysql_select_db("testdb",$conn) or die(mysql_error());

define("ADAY", (60*60*24));
if (!checkdate($_POST['month'], 1, $_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 LANGUAGE="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 Combination</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]."";
}
?>
</select>
<select name="year">
<?php
for ($x=2008; $x<=2020; $x++) {
echo "<option";
if ($x == $year) {
echo " SELECTED";
}
echo ">$x";
}
?>
</select>
<input type="submit" value="Go!">
</form>
<br>
<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<TABLE BORDER=1 CELLPADDING=5 width=95%><tr>\n";
foreach ($days as $day) {
echo "<TD BGCOLOR=\"#CCCCCC\" 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 = "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) or die(mysql_error());

if (@mysql_num_rows($chkEvent_res) > 0) {
while ($ev = @mysql_fetch_array($chkEvent_res)) {
$event_title = stripslashes($ev['event_title']);
$event_title_txt .= "$event_title <br>";
}
}

echo "<td><a href=\"javascript:eventWindow('event_list_events.p hp?m=".$month."&d=".$dayArray['mday']."&y=$year');\">".$dayArray['mday']."</a> <br> <br> $event_title_txt </td>\n";

unset($event_title_txt);

$start += ADAY;
}
}
echo "</tr></table>";
?>
</body>
</html>
[/PHP]


Here is my code for to add an event

[PHP]
<html>
<head>
<title>Show/Add Events</title>
<head>
<body>
<h1>Show/Add Events</h1>
<?php
$conn = mysql_connect("localhost", "nomad1", "nomad1") or die(mysql_error());
mysql_select_db("testdb",$conn) or die(mysql_error());

//add any new event
if ($_POST[op] == "do") {
$event_date = $_POST[y]."-".$_POST[m]."-".$_POST[d]." ".$_POST[event_time_hh].":".$_POST[event_time_mm].":00";

$insEvent = "INSERT INTO calendar_events VALUES('', '$_POST[event_title]', '$_POST[event_shortdesc]', '$event_date')";
@mysql_query($insEvent) or die(mysql_error());

}

//show events for this day
$getEvent = "SELECT event_title, event_shortdesc, date_format(event_start, '%l:%i %p') as fmt_date FROM calendar_events WHERE month(event_start) = '$_GET[m]' AND dayofmonth(event_start) = '$_GET[d]' AND year(event_start) = '$_GET[y]' ORDER BY event_start";

$getEvent_res = @mysql_query($getEvent) or die(mysql_error());

if (@mysql_num_rows($getEvent_res) > 0) {
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 .= "<P><strong>$fmt_date</strong>: $event_title<br>$event_shortdesc";

}

}

if ($event_txt != "") {
echo "<P><strong>Today's Events:</strong>
$event_txt
<hr noshade width=80%>";
}

// show form for adding an event
echo "<form method=post action=\"$_SERVER[PHP_SELF]\">
<P><strong>Would you like to add an event?</strong><br>Complete the form below and press the submit button to add the event and refresh this window.</p>
<p><strong>Event Title:</strong><br>
<input type=text name=event_title size=25 maxlength=25>
<p><strong>Event Description:</strong><br>
<input type=text name=event_shortdesc size=25 maxlength=255>
<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=$_GET[m]>
<input type=hidden name=d value=$_GET[d]>
<input type=hidden name=y value=$_GET[y]>
<input type=hidden name=op value=do>
<br><br>
<input type=submit name=submit value=\"Add Event\">
</form>";
?>
</body>
</html>
[/PHP]

This is my first db so I have a question.
How does the php file know where to look for the db. Do I need to add any info tellig where it is at?

Any help would be great.
Thanks
damon
Oct 3 '08 #1
Share this Question
Share on Google+
6 Replies


Atli
Expert 5K+
P: 5,058
Hi.

What kind of HTTP servers and MySQL servers are you using on your test server and on the "live" server?
What are the differences between them?

Have you created the database tables and users on your new server?

This is my first db so I have a question.
How does the php file know where to look for the db. Do I need to add any info tellig where it is at?
The location of the database is in your mysql_connect call. The first parameter tells it *where* the database is. Which in your case is "localhost" (also known as IP address "172.0.0.1")
Oct 4 '08 #2

nomad
Expert 100+
P: 664
What kind of HTTP servers and MySQL servers are you using on your test server and on the "live" server?
What are the differences between them?
I hope this is what you want. on my test sever:
Server version: 5.0.45-community-nt
phpMyAdmin - 2.10.3 :
MySQL client version: 5.0.45

Live server:
phpMyAdmin - 2.8.0.1
MySQL - 5.0.51a-log



Have you created the database tables and users on your new server?
I did that. and I know the db is created because I can see it.


The location of the database is in your mysql_connect call. The first parameter tells it *where* the database is. Which in your case is "localhost" (also known as IP address "172.0.0.1")
When I look up the process list and under Host it does not list Localhost but gives a different address should I use that in stead?
some thing like this
main25.int.bizland.net:(some number here



If you need any more info please ask me and I will try to provide it.
Thank
damon
Oct 7 '08 #3

nomad
Expert 100+
P: 664
I hope this solved the problem I had to enable the CGI script.
Oct 8 '08 #4

nomad
Expert 100+
P: 664
I hope this solved the problem I had to enable the CGI script.

Now I get this error;
Access denied for user 'pantana'@'boscgixxxx.eigbox.net' (using password: YES)
can anyone help please

thanks
nomad
Oct 9 '08 #5

Atli
Expert 5K+
P: 5,058
That would indicate that you are able to connect, but the MySQL login info is incorrect.

Make sure that the user name and password are in fact correct, and the the user has access to the database.

If that fails, you could try accessing the database as root and GRANT the user access to you database.
Oct 9 '08 #6

nomad
Expert 100+
P: 664
That would indicate that you are able to connect, but the MySQL login info is incorrect.

Make sure that the user name and password are in fact correct, and the the user has access to the database.

If that fails, you could try accessing the database as root and GRANT the user access to you database.
Once again thanks Atli and everyone else that help me.
password was wrong.

nomad
I really need to learn PHP so I can get a better job.
Oct 10 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.