I get the message:
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
'12:00,25.32,1015.19,42.32,200.0,1.29,2.25,7.11,11.58,5.97,3.5,0.0,0.0,0.0,0.0,37'
at line 2
relevant code:
$con = mysql_connect("127.0.0.1", "username", "password") or die(mysql_error());
mysql_select_db("database",$con) or die (mysql_error());
//readFmi() returns an array of strings with values separated by commas
$array = readFmi($xml);
$cols = 'date, Temperature, Pressure, Humidity, WindDirection, WindSpeedMS,
MaximumWind, WindGust, DewPoint, TotalCloudCover, LowCloudCover, MediumCloudCover,
HighCloudCover, Precipitation1h, PrecipitationAmount, RadiationLW, RadiationGlobal,
RadiationNetTopAtmLW';
foreach($array as $a){
$a2 = mysql_real_escape_string($a);
echo $a2."<br>";
mysql_query("INSERT INTO forecastsFMI ($cols)
VALUES ($a2)") or die (mysql_error());
}
mysql_close($con);
$a when printed looks like this
2013-06-24 12:00,25.32,1015.19,42.32,200.0,1.29,2.25,7.11,11.58,5.97,3.5,0.0,0.0,0.0,0.0,375.85,550.09,-260.6
$cols are the exact same ones as found in the table in the database, I set them all to be varchar for now, while trying to figure out where i have made my mistake(s). I have been counting the fields in the db and values to see if that is where i have gone wrong, tried to change the format of the string itself and tried to change and tweak different parts of the code, without any difference in result. What might cause this?
Thank you //Tobias