Perhaps I am missing something obvious or maybe it's not so obvious, but for some reason the following code won't insert into my mySQL database.
I am including all of the code from the page.
Any thoughts on why it won't work?
<?php
// addrace.php - add a new race results
?>
<?php
// includes
include("../includes/config.php");
include("../includes/functions.php");
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
?>
<title>Race Results: Add Race Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../css/styles.css" type="text/css">
<script language="javascript" src="../scripts/CascadeMenu.js"></script>
<script language="JavaScript" src="../scripts/ts_picker2.js"></script><!-- Date input popup (American Format) reworked by Richard Perry -->
</head>
<body OnLoad="InitMenu()" Onclick="HideMenu(menuBar)" ID="Bdy" bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<!-- standard page header begins -->
<?php
error_reporting (1);
// form not yet submitted
// display initial form
if (!$submit)
{
?>
<form action="<? echo $PHP_SELF; ?>" method="POST" name="tstest">
<table width="799" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
<tr>
<td width="339" height="112" valign="top" bgcolor="#0066cc"> </td>
<td width="460" valign="top" rowspan="2">
<?php include ("../includes/nav.php3");
?>
</td>
</tr>
<tr>
<td height="16"></td>
</tr>
<tr>
<td height="12"></td>
<td></td>
</tr>
</table>
<table width="800" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="10" bgcolor="#ffffff" height="25">
<td valign="middle" colspan="2" class="raceresutlstitle" bgcolor="#ffffff">Admin
> Add a Race</td>
</tr>
<tr>
<td width="10" bgcolor="#CCCCCC">
<td width="131" valign="middle" height="25" class="raceresutlstitle" bgcolor="#CCCCCC">Race
Date:</td>
<td width="660" valign="middle" bgcolor="#CCCCCC">
<input type="Text" name="RaceDate" value="">
<a href="javascript:show_calendar2('document.tstest.RaceDate', document.tstest.RaceDate.value);"><img src="../images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a>
</td>
</tr>
<tr>
<td width="10">
<td valign="middle" height="25" class="raceresutlstitle">Race Name:</td>
<td valign="middle">
<input type="text" name="RaceName">
</td>
</tr>
<tr>
<td width="10" bgcolor="#CCCCCC">
<td valign="middle" height="25" class="raceresutlstitle" bgcolor="#CCCCCC">Race
Distance:</td>
<td valign="middle" bgcolor="#CCCCCC">
<?php
// populates race distance drop-down list
$get_racedistid = mysql_query("SELECT * FROM RaceDistance order by RaceDistName");
echo " <select name=\"RaceDistID\">\n";
while ($myrow = mysql_fetch_array($get_racedistid)) {
echo ' <option value="'.$myrow["RaceDistID"].'">'.$myrow["RaceDistName"]."</option>\n";
}
echo " </select>\n";
?>
</td>
</tr>
<tr>
<td width="10">
<td valign="middle" height="25" class="raceresutlstitle">Race Type:
</td>
<td valign="middle" class="newstxt">
<?php
// populates race type drop-down list
$get_racetypeid = mysql_query("SELECT * FROM RaceType order by RaceTypeName");
echo " <select name=\"RaceTypeID\">\n";
while ($myrow = mysql_fetch_array($get_racetypeid)) {
echo ' <option value="'.$myrow["RaceTypeID"].'">'.$myrow["RaceTypeName"]."</option>\n";
}
echo " </select>\n";
?>
</td>
</tr>
<tr>
<td width="10" bgcolor="#CCCCCC">
<td valign="middle" height="25" class="raceresutlstitle" bgcolor="#CCCCCC">Race
Time:</td>
<td valign="middle" bgcolor="#CCCCCC">
<input type="text" name="RaceTime">
<span class="hdtxt"> (HH:MM:SS) </span></td>
</tr>
<tr>
<td width="10">
<td valign="middle" height="25" class="raceresutlstitle">Race Pace:</td>
<td valign="middle">
<input type="text" name="RacePace">
<span class="hdtxt">(min/mile)</span></td>
</tr>
<tr>
<td width="10" bgcolor="#CCCCCC">
<td valign="middle" height="25" class="raceresutlstitle" bgcolor="#CCCCCC">#
of Comp.:</td>
<td valign="middle" bgcolor="#CCCCCC">
<input type="text" name="RaceNumbComp">
</td>
</tr>
<tr>
<td width="10" bgcolor="#ffffff">
<td valign="middle" height="25" class="raceresutlstitle" bgcolor="#ffffff">Race
Place:</td>
<td valign="middle" bgcolor="#ffffff">
<input type="text" name="RacePlace">
</td>
</tr>
<tr>
<td width="10" bgcolor="#cccccc">
<td valign="middle" height="25" class="raceresutlstitle" bgcolor="#cccccc">Race
City:</td>
<td valign="middle" bgcolor="#cccccc">
<?php
// populates city drop-down list
$get_cityid = mysql_query("SELECT * FROM City order by CityName");
echo " <select name=\"CityID\">\n";
while ($myrow = mysql_fetch_array($get_cityid)) {
echo ' <option value="'.$myrow["CityID"].'">'.$myrow["CityName"]."</option>\n";
}
echo " </select>\n";
?>
</td>
</tr>
<tr>
<td width="10" bgcolor="#ffffff">
<td valign="middle" height="25" class="raceresutlstitle" bgcolor="#ffffff">Race
State:</td>
<td valign="middle" bgcolor="#ffffff">
<?php
// populates state drop-down list
$get_stateid = mysql_query("SELECT * FROM State order by StateName");
echo " <select name=\"StateID\">\n";
while ($myrow = mysql_fetch_array($get_stateid)) {
echo ' <option value="'.$myrow["StateID"].'">'.$myrow["StateName"]."</option>\n";
}
echo " </select>\n";
?>
</td>
</tr>
<tr>
<td width="10" bgcolor="#cccccc">
<td valign="middle" height="25" class="raceresutlstitle" bgcolor="#cccccc">Race
Report:</td>
<td valign="middle" bgcolor="#cccccc">
<textarea name="RaceReport" cols="50" rows="3"></textarea>
</td>
</tr>
<tr align="center">
<td width="10">
<td valign="middle" colspan="2" height="28">
<input type="submit" name="Submit" value="Submit">
</td>
</tr>
</table>
</form>
<?php
}
else
{
// set up error list array
$errorList = array();
$count = 0;
// validate text input fields
if (!$RaceDate) { $errorList[$count] = "Invalid entry: Race Date"; $count++; }
if (!$RaceName) { $errorList[$count] = "Invalid entry: Race Name"; $count++; }
if (!$RaceDistID) { $errorList[$count] = "Invalid entry: Race Distance"; $count++; }
if (!$RaceTypeID) { $errorList[$count] = "Invalid entry: Race Type"; $count++; }
if (!$RaceTime) { $errorList[$count] = "Invalid entry: Race Time"; $count++; }
if (!$RacePace) { $errorList[$count] = "Invalid entry: Race Pace"; $count++; }
if (!$RaceNumbComp) { $errorList[$count] = "Invalid entry: Number of Competitors"; $count++; }
if (!$CityID) { $errorList[$count] = "Invalid entry: CityID"; $count++; }
if (!$StateID) { $errorList[$count] = "Invalid entry: StateID"; $count++; }
if (!$RaceReport) { $errorList[$count] = "Invalid entry: RaceReport"; $count++; }
// check for errors
// if none found...
if (sizeof($errorList) == 0)
{
// generate and execute query
$query = "INSERT INTO RaceResults (RaceDate, RaceName, RaceDistID, RaceTypeID, RaceTime, RacePace, RaceNumbComp, RacePlace, CityID, StateID, RaceReport) VALUES('$RaceDate', '$RaceName', '$RaceDistID', '$RaceTypeID', '$RaceTime', '$RacePace', '$RaceNumbComp', '$RacePlace', '$CityID', '$StateID', '$RaceReport'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// print result
echo "<font size=3>Update successful. <a href=listraces.php>Go back to the main menu</a>.</font>";
// close database connection
mysql_close($connection);
}
else
{
// errors found
// print as list
echo "<font size=-1>The following errors were encountered: <br>";
echo "<ul>";
for ($x=0; $x<sizeof($errorList); $x++)
{
echo "<li>$errorList[$x]";
}
echo "</ul></font>";
}
}
?>