Code: Select all
$today = getdate();
$day = $today['mday'];
$month = $today['mon'];
$year = $today['year'];
$mtharr = array("January","February","March","April","May","June","July","August","September","October","November","December");
// Create an empty array to hold the error messages.
$arrErrors = array();
//Only validate if the Submit button was clicked.
if (!empty($_POST['Submit'])) {
// Each time there's an error, add an error message to the error array
// using the field name as the key.
if (count($arrErrors) == 0) {
// If the error array is empty, there were no errors.
// Insert form processing here.
$host = " ";
$user = " ";
$pass = " ";
$dbname = " ";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
$startdate = mktime(0, 0, 0, $TSpickMonth, $TSpickDay, $TSpickYear);
$enddate = mktime(0, 0, 0, $TFpickMonth, $TFpickDay, $TFpickYear);
$sql_query = mysql_query("INSERT INTO trip_log(startdate, enddate) VALUES ('$_POST[startdate]', '$_POST[enddate]')")
or die (mysql_error());
header("Location: /index.php?page=Trip_Log");
} else {
// The error array had something in it. There was an error.
// Start adding error text to an error string.
$strError = '<div class="formerror"><p><img src="/uploads/images/triangle_error.gif" width="16" height="16" hspace="5" alt="">Please check the following and try again:</p><ul>';
// Get each error and add it to the error string
// as a list item.
foreach ($arrErrors as $error) {
$strError .= "<li>$error</li>";
}
$strError .= '</ul></div>';
}
}
echo '<style>';
echo 'label {
}';
echo '.formerror {
border: 1px solid red;
background-color : #FFCCCC;
width: auto;
padding: 0px 0;
}';
echo '.errortext {
padding-left: 80px;
font: bold smaller sans-serif;
}';
echo '</style>';
echo '<form method="post" action="',$_SERVER['REQUEST_URI'],'">';
echo '<label for="trip start">Trip Start:</label><br />';
echo '<select name="TSpickMonth" size="1">';
for ($i=1;$i<=12;$i++) { echo '<option value="$i"'; if ($i == $month) echo ' selected'; echo '>',$mtharr[$i-1],'</option>'; }
echo '</select>';
echo '<select name="TSpickDay" size="1">';
for ($i=1;$i<=31;$i++) { echo '<option value="$i"'; if ($i == $day) echo ' selected'; echo '>',$i,'</option>'; }
echo '</select>';
echo '<select name="TSpickYear" size="1">';
for ($i=2002;$i<=2010;$i++) { echo '<option value="$i"'; if ($i == $year) echo ' selected'; echo '>',$i,'</option>'; }
echo '</select>';
echo '<label for="trip finish">Trip Finish:</label><br />';
echo '<select name="TFpickMonth" size="1">';
for ($i=1;$i<=12;$i++) { echo '<option value="$i"'; if ($i == $month) echo ' selected'; echo '>',$mtharr[$i-1],'</option>'; }
echo '</select>';
echo '<select name="TFpickDay" size="1">';
for ($i=1;$i<=31;$i++) { echo '<option value="$i"'; if ($i == $day) echo ' selected'; echo '>',$i,'</option>'; }
echo '</select>';
echo '<select name="TFpickYear" size="1">';
for ($i=2002;$i<=2010;$i++) { echo '<option value="$i"'; if ($i == $year) echo ' selected'; echo '>',$i,'</option>'; }
echo '</select>';
echo '</p>';
echo $strError;
echo '<p>';
echo '<input type="submit" name="Submit" value="Submit">';
echo '</p>';