I'm having some trouble inserting timestamps into a mysql table. I am inserting entries into a table using the following query:
$query = <<<SQLQUERY
INSERT INTO Events
SET
start_date = FROM_UNIXTIME($startDates[$x]),
end_date = FROM_UNIXTIME($endDates[$x]),
title = "$titles[$x]",
location = "$locations[$x]"
SQLQUERY;
Note that start_date and end_date were created with type DATE, in mysql.
In another file, I am trying to select and display the records from this table using the following code
$query_str = "SELECT UNIX_TIMESTAMP(start_date), UNIX_TIMESTAMP(end_date), title, location FROM Events";
$result = $conn->query($query_str);
//left out a few lines here
while (($row_data = @$result->fetch_assoc()) !== NULL)
{
echo "<tr><td>{$row_data['start_date']}";
if($row_data['end_date'] != NULL)
echo " - " . date('M d', $row_data['end_date']). "</td>";
else
echo "</td>";
echo "<td>{$row_data['title']}</td><td>{$row_data['location']}</td></tr>\n";
}//end while
I get the title and locations back correctly, but the cells for the dates all come back empty. Anyone have any idea what I'm doing wrong?