I have a PHP form that lists all the activities in each month. When the form, eventPage.php, is first loaded, I received this error:
Notice: Undefined index: Month in F:\Foundation\alumni\evtSearchPage.php on line 290
because I have this:
$slMonth = $_GET["Month"];
in my PHP tag. Is there a way to set this $slMonth variable to a default value on the first time the page is load? If not, is there a way put a default value in form's drop down list. Below is my form code:
<form name="evtSearch" method="get" action="<? $_SERVER['PHP_SELF'] ?>">
<select name="Month" onChange=formHandler() size=1>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
</form>
Here's the code for the PHP tag:
<?PHP
//********* Variable Declaration *********************************************
$slMonth = $_GET["Month"];
//******Testing and Find Records***********************************************
echo "Month is: ".$slMonth."<br>";
@ $db = mysql_connect("***", "***", "***");
if (!$db) {
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("alumni");
//*****************Generate Result*******************************************
$query = "select from event where Month like '%".$slMonth."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo '<table width="548" border="0" cellspacing="-1" cellpadding="-1">';
for ($i = 0; $i < $num_results; $i++){
if ($i == 0){
$pt = $i;
}
if ($pt != $i){
$bkgColor = "#CCFFFF";
$pt += 2;
}
else{
$bkgColor ="#CCCCCC";
}
$row = mysql_fetch_array($result);
if($row["Day"] > 5 && $row["Day"] != 21 && $row["Day"] !=31){
$dyHolder = $row["Day"]."th";
}
elseif($row["Day"] = 3){
$dyHolder = $row["Day"]."rd";
}
elseif($row["Day"] = 3){
$dyHolder = $row["Day"]."nd";
}
else{
$dyHolder = $row["Day"]."st";
}
echo '<tr class="bodycopy">';
echo '<td width="294" bgcolor="'.$bkgColor.'">';
echo '<ul><li><b>'.$row['Month']." ".$dyHolder.'</b> - '.$row["Event"].'</li></ul>';
echo '</td>';
echo '<td width="113" bgcolor="'.$bkgColor.'">'.$row["Place"].'</td>';
echo '<td width="134" bgcolor="'.$bkgColor.'">'.$row["Location"].'</td>';
echo '</td></tr>';
}
echo '</table>';
echo "<br>";
?>
Many thanks for your help!
Lauj