Data from mktime not inserting to MySQL database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
outdoorxtreme1
Forum Newbie
Posts: 18
Joined: Tue Mar 21, 2006 10:59 am

Data from mktime not inserting to MySQL database

Post by outdoorxtreme1 »

I am ahing a problem with the following code. When I go to my data base the data for startdate and enddate fileds are 0. What am I doing wrong? Can someone please help me? Thanks.

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>';
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

cant you use the CURDATE mysql functio?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you're trying to insert nonexistant post variables.

I believe you want to use $startdate and $enddate (after running through date())
outdoorxtreme1
Forum Newbie
Posts: 18
Joined: Tue Mar 21, 2006 10:59 am

Post by outdoorxtreme1 »

I'm kinda a newbe at this. Do I need to move some of my code?
Post Reply