guzmanistan
Weaksauce
- Joined
- Jun 3, 2005
- Messages
- 92
Hi all,
Thanks for the help ahead of time. So, I'm working on this site and am basically trying to work a php script to upload a CSV to a MySQL database. It works fine except for the timestamp (column = cdatetime). I know that the format in the DB is "YYYY-MM-DD HH:MM:SS", and have changed the format in the CSV accordingly. I've tried a crap ton of different ways to format it to read it in thinking the DB might be converting the numbers over, but its just not reading in. I'm getting this error when performing the operation:
Thanks again - Guzmanistan
Relevant code:
Thanks for the help ahead of time. So, I'm working on this site and am basically trying to work a php script to upload a CSV to a MySQL database. It works fine except for the timestamp (column = cdatetime). I know that the format in the DB is "YYYY-MM-DD HH:MM:SS", and have changed the format in the CSV accordingly. I've tried a crap ton of different ways to format it to read it in thinking the DB might be converting the numbers over, but its just not reading in. I'm getting this error when performing the operation:
This makes me think its something with my code since its not uploading the datetime value (the first value before the comma) before the spacer. Does anyone have any ideas? Is there some wierd formatting thing I'm missing out on?Could not update the values! You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '18:01:19, 54.255, 57.376, 56.208)' at line 2
Thanks again - Guzmanistan
Relevant code:
Code:
while (!feof($file_handle) ) {
$data = fgetcsv($file_handle, 1024);
echo $data[0].'<br>';
echo $data[1].'<br>';
echo $data[2].'<br>';
echo $data[3].'<br>';
// Trying out a bunch of different date format techniques
echo $datetime = explode(' ',$data[0]);
echo $date = explode('-',$datetime[0]);
echo $time = explode(':',$datetime[1]);
$year = $date[0];
echo $year.'<br>';
$month = $date[1];
echo $month.'<br>';
$day = $date[2];
echo $day.'<br>';
$hour = $time[0];
echo $hour.'<br>';
$min = $time[1];
echo $min.'<br>';
$sec = $time[2];
echo $sec.'<br>';
//
$datetime_fin = date("Y-m-d H:i:s", mktime($hour, $min, $sec, $month, $day, $year));
$datetime2 = mktime($hour, $min, $sec, $month, $day, $year);
$mysqldate = date("Y-m-d H:i:s", $data[0]);
echo 'date fxn'.$mysqldate.'<br>';
echo 'date fxn:'.$datetime_fin.'<br>';
echo 'mktime fxn:'.$datetime2.'<br>';
//echo strtotime($data[0]);
//$datetime = date('Y-m-d H:i:s',$date[0]);
//$datetime = strtotime($data[0]);
//
//
$n_id=1;
$query = "INSERT INTO nodedata (nodeid, cdatetime, tempsoilx, tempairx, tempwaterx)
VALUES ($n_id, $datetime_fin, $data[1], $data[3], $data[2])";
$result = mysql_query($query);
if($result) {
echo'<p style="color:green;">All values were calculated and updated in the table</p>';
}
else {
echo'<p style="color:red;">Could not update the values! '.mysql_error();
echo'</p>';
}
} //closing WHILE LOOP
fclose($file_handle);