Creating a PHP calendar

i’m trying to create an easy-to-update calendar with php and an SQL database. i downloaded a simple script at this website, which ultimately serves its general purpose because i got it to work the first time with no problems. well, i’m still generally new to php, and this is so far turning into a decent learning experience. i’ve done a few small scripts, and i’m also trying to learn some asp, so i’ve been more willing to toy around with the code and do the trial by error method.

ANYWAYS…

i’m trying to add some extra fields into the form and get them to …well, A: record into the database, and B: show up on the page. i’m almost positive the problem lies within my coding, because all of the tables i created are there and fine. but just in case, i’m going to post some of this code up so that maybe i can get some feedback on what direction i should be looking in. currently, the form shows everything, but when i fill out the information and hit submit, it says it’s added the records but it doesn’t show them in the database or the webpage listing.

this is the php coding for the admin.php page:

include("config.php");
include("protection.php"); 
$today_day = date("d");
$today_month = date("m");
$today_year = date("Y");
?>
<html>
<head>
<title> ~*~ PHPCalendar ~*~ </title>
<STYLE>
<!--
BODY    { background-color : #B0D1E0; scrollbar-base-color: #8FBED4; scrollbar-face-color: #8FBED4; scrollbar-track-color: #8FBED4; scrollbar-arrow-color: #477E97; scrollbar-highlight-color: #B0D1E0; scrollbar-3dlight-color: #B0D1E0; scrollbar-shadow-color: #477E97; scrollbar-darkshadow-color: #477E97; }
A:link, A:visited { color : #101084; text-decoration : none; font-weight: bold; }
A:hover, A:active { color : #000040; text-decoration : underline; font-weight: bold; }
BODY, p, table, tr, td, ul, li {font-family: verdana; font-size: 10px; color: #000000; }
H1 { font-size : 14; color : #0D7CAF; font-weight : bold; }
input, textarea, select { font-family: verdana; font-size: 10px; background-color: #C2E4F4; font-weight: bold; color: #000040; border: 1px solid #477E97; }
input.button { font-family: verdana; font-size: 12px; background-color: #000040; font-weight: bold; color: #C2E4F4; border: 1px solid #477E97; }
-->
</STYLE>
</head>

<body topmargin="10" leftmargin="0">
<center>
<table width="95%" border="0">
<tr><td width="224px" style="background-color: #8FBED4; border: 1px solid #404040; padding:5px; margin:5px;" valign="top">
<center><A HREF="http://codegrrl.com" target="_blank"><img src="logo.gif" border="0"></A></center>
<p align="right"><a href="admin.php">add an item</a><br>
<a href="admin.php?action=edit">edit/delete items</a><br>
<a href="admin.php?action=logout">logout</a>
</p>
<p align="left">You currently have:
<?
// get this month count
$querymonth="SELECT id FROM $table WHERE (day >= $today_day 
						AND month = $today_month 
						AND year = $today_year
						AND done != 'y')
						OR (day >= $today_day 
						AND month = $today_month 
						AND year = '0'
						AND done != 'y')";
$resultmonth=mysql_query($querymonth);
$nummonth=mysql_numrows($resultmonth);
// get this year count
$queryyear="SELECT id FROM $table WHERE ( month > $today_month 
						AND year = $today_year
						AND done != 'y')
						OR ( month > $today_month 
						AND year = $today_year
						AND done != 'y')";
$resultyear=mysql_query($queryyear);
$num_year=mysql_numrows($resultyear);
$numyear = $num_year + $nummonth;
// get today count
$querytoday="SELECT * FROM $table WHERE (day = $today_day 
						AND month = $today_month 
						AND year = $today_year
						AND done != 'y')
						OR (day = $today_day 
						AND month = $today_month 
						AND year = '0'
						AND done != 'y')";

$resulttoday=mysql_query($querytoday);
$numtoday=mysql_numrows($resulttoday);
?>
<br><b><?=$numyear?></b>
<? if ($numyear == '1') { ?> event
<? } else { ?> events
<? } ?> until the end of the year
<br><b><?=$nummonth?></b> 
<? if ($nummonth == '1') { ?> event
<? } else { ?> events
<? } ?> until the end of the month
<br><b><?=$numtoday?>
<? if ($numtoday == '1') { ?> event
<? } else { ?> events
<? } ?> today<? if ($numtoday != '0') ?>:
<? $i=0;
while ($i < $numtoday) {
$city_today=mysql_result($resulttoday,$i,"city");
$state_today=mysql_result($resulttoday,$i,"state");
$venue_today=mysql_result($resulttoday,$i,"venue");
$time_today=mysql_result($resulttoday,$i,"time");
?>
<br>&nbsp;&nbsp;&nbsp;&nbsp; - <?=$city_today?>,<?=$state_today?> at <?=$venue_today?> - <?=time_today?>
<? 
++$i;
} 
?>
</b>
</td><td width="*">
<center>

<?
if (!$action || $action== "login"){
?>
<h1>Add a new Item</h1>

<div align="center"><form action="admin.php" method="post">
<input type="hidden" name="action" value="addthing2">
<table border="0" cellspacing="0" cellpadding="2">
<tr><td align="center">Day: <input type="text" name="day" size="2" maxlength="2"></td>
<td align="center">Month (numeric format): <input type="text" name="month" size="2" maxlength="2"></td>
<td align="center">Year (four digit format): <input type="text" name="year" size="4" maxlength="4"></td>
<td>&nbsp;</td></tr>
<tr><td align="center">Venue: <input type="text" name="venue" size="20"></td>
<td align="center">City: <input type="text" name="city" size="20"></td>
<td align="center">State: <input type="text" name="state" size="20"></td>
<td align="center">Time: <input type="text" name="time" size="6"></td></tr>
<tr><td colspan="3" align="center"><input type="Submit" class="button"></td></tr></table>
</form></div>
<?
} elseif ($action == "addthing2"){
$query = "INSERT INTO $table VALUES ('','$day','$month','$year','$venue','$city','$state','$time','n')";
mysql_query($query);
print "<p>Successfully added!</p>";




} elseif ($action == "edit"){ ?>
<h1>Edit an Item</h1>

<div align="center"><form action="admin.php" method="post">
<input type="hidden" name="action" value="select">
<table border="0" cellspacing="0" cellpadding="2">
<tr><td align="center">Day: <input type="text" name="day" size="2" maxlength="2"></td>
<td align="center">Month (numeric format): <input type="text" name="month" size="2" maxlength="2"></td>
<td align="center">Year (four digit format): <input type="text" name="year" size="4" maxlength="4"></td>
<td>&nbsp;</td></tr>
<tr><td align="center">Venue: <input type="text" name="venue" size="20"></td>
<td align="center">City: <input type="text" name="city" size="20"></td>
<td align="center">State: <input type="text" name="state" size="2" maxlength="2"></td>
<td align="center">Time: <input type="text" name="time" size="6"></td></tr>
<tr><td colspan="3" align="center"><input type="Submit" class="button"></td></tr></table>
</form></div>

<? } elseif ($action == "select"){ ?>
<h1>Edit an Item</h1> <?
if ($day == "")
{$day = '%';}

if ($month == "")
{$month = '%';}

if ($year == "")
{$year = '%';}

if ($venue == "")
{$venue = '%';}

if ($city == "")
{$city = '%';}

if ($state == "")
{$state = '%';}

if ($time == "")
{$time = '%';}

$result = mysql_query ("SELECT * FROM $table WHERE day LIKE '$day' AND month LIKE '$month' AND year LIKE '$year' AND venue LIKE '%$venue%' AND city LIKE '$city' AND state LIKE '$state' AND time LIKE '$time'");

if ($row = mysql_fetch_array($result)) {

do { 
$done=$row["done"];
?>
<div align="center"><form action="admin.php" method="post">
<input type="hidden" name="action" value="modify">
<input type="hidden" name="id" value="<?=$row["id"]?>">
<table border="0" cellspacing="0" cellpadding="2">
<tr><td align="center">Day: <input type="text" name="day" size="2" value="<?=$row["day"]?>" maxlength="2"></td>
<td align="center">Month: <input type="text" name="month" size="2" value="<?=$row["month"]?>" maxlength="2"></td>
<td align="center">Year: <input type="text" name="year" size="4" value="<?=$row["year"]?>" maxlength="4"></td>
<td>&nbsp;</td></tr>
<tr><td align="center">Venue:<input type="text" name="venue" size="20" value="<?=$row["venue"]?>"></td>
<td align="center">City:<input type="text" name="venue" size="20" value="<?=$row["city"]?>"></td>
<td align="center">State:<input type="text" name="venue" size="20" value="<?=$row["state"]?>"></td>
<td align="center">Time:<input type="text" name="venue" size="20" value="<?=$row["time"]?>"></td></tr>
<tr><td align="center" colspan="4">Has this show already occurred?
<select name="done">
<? if ($done == 'y') { ?>
<option value="n">No</option>
<option value="y" SELECTED>Yes</option>
<? } else { ?>
<option value="n" SELECTED>No</option>
<option value="y">Yes</option>
<? } ?>
</select></td></tr>
<tr><td align="right">Action: </td><td colspan="2"><select name="what" class="button">
<option value="up" SELECTED>Update</option>
<option value="del">Delete</option></select></td></tr>
<tr><td colspan="3"><input type="Submit" class="button"></td></tr></table>
</form></div>

<?} while($row = mysql_fetch_array($result));
} else {print "<p>Sorry, no records were found! Please try again. <br>
Tip: you don't have to fill in all the fields in the Edit form. Filling in just one or two will return all dates with that information, it works like a search form. :)</p>";}



} elseif ($action == "modify"){ 

echo "<p>This date was"; 

if ($what == "up"){

$query = "UPDATE $table SET day='$day', month='$month', year='$year', venue='$venue', city='$city', state='$state', time='$time', done='$done' WHERE id='$id'";

mysql_query($query);

echo "&nbsp;updated"; 

} elseif ($what == "del"){
$query = "DELETE from $table WHERE id='$id'";
mysql_query($query);

echo "&nbsp;deleted"; 

}

echo "&nbsp;successfully!</p>"; 


 } elseif ($what == "invalid"){ ?>
<p><B>Invalid login name or password!</B><BR>Please press the back button on your browser to try again.</p>




<? }  ?>
<center></td></tr></table>
<div width="90%" style="background-color: #477E97; border: 1px solid #404040; padding:5px; margin:5px;" align="center">
&copy; Copyright <a href="http://unfloopy.net" target="_blank">Louise</a>, 2003. All Rights Reserved.<br>PHPCalendar v1.0</div>
</center></body></html>

this is the code for my list.php page (or the page where all of the info is supposed to show up in the end)

<p><b>Calendar:</b><br>

<? include("config.php");

$today_day = date("d");
$today_month = date("m");
$today_year = date("Y");

$query="SELECT * FROM $table WHERE ( month = $today_month AND year = $today_year ) OR ( month = $today_month AND year = '0' ) ORDER BY day";
$result=mysql_query($query);
$num=mysql_numrows($result);

$i=0;
while ($i < $num) {
$day=mysql_result($result,$i,"day");
$venue=mysql_result($result,$i,"venue");
$city=mysql_result($result,$i,"city");
$state=mysql_result($result,$i,"state");
$time=mysql_result($result,$i,"time");
$done=mysql_result($result,$i,"done");
$day = sprintf("%02.0f", $day);

if ($day == $today_day){ 
	if ($done == 'y'){ ?>
	<br><b><strike><?=$day?>/<?=$today_month?>/<?=$today_year?> - <?=$venue?> <?=$city?> <?=$state?> <?=$time?></strike></b>
	<? } else { ?>
	<br><b><?=$day?>/<?=$today_month?>/<?=$today_year?> - <?=$venue?> <?=$city?> <?=$state?> <?=$time?></b>
	<? }
 } elseif ($day < $today_day){ ?>
<br><strike><?=$day?>/<?=$today_month?>/<?=$today_year?> - <?=$venue?> <?=$city?> <?=$state?> <?=$time?></strike>
<? } elseif ($done == 'y'){ ?>
<br><strike><?=$day?>/<?=$today_month?>/<?=$today_year?> - <?=$venue?> <?=$city?> <?=$state?> <?=$time?></strike>
<? } else { ?>
<br><?=$day?>/<?=$today_month?> - <?=$venue?> <?=$city?> <?=$state?> <?=$time?>
<? }
++$i;
} ?>
<p align="center">Powered by <a href="http://codegrrl.com" target="_blank">PHPCalendar</a></p>

…and just in case, this was the automatic create-a-table form that came with the thing. i’m pretty sure my sql tables are ok though, i’m just posting this as reference.

<?
require("config.php");

mysql_query("CREATE TABLE $table (id int(6) NOT NULL auto_increment, day int(2) NOT NULL, month int(2) NULL, year int(4) NULL, state text NOT NULL, venue text NOT NULL, time text NOT NULL, done text NOT NULL, KEY id (id))") or die(mysql_error());

print ("<p>Congratulations!! The table was created sucessfully. Now delete this file from your server and login to your <a href=\"admin.php\">Admin Panel</a>.</p>");
mysql_close($db);
?>

the original code is at that link above… any help i could get at ALL would be greatly appreciated. hopefully i’m on the right track…