While creating a statistics program I'm keeping track how many aircraft visit an aerodrome per hour.
My script calculates the number of flights in the last hour and saves this to the database. my i keep getting mysql syntax error if I copy the statement in phpmyadmin it works
$date = 2013091713;
//$date = date('YmdH', mktime(date('H')));
$sql = '';
foreach ($aerodrome as $icao => $value) {
$sql .= "INSERT INTO flightsperhour(date, aerodrome, inbound, outbound)
VALUES('". $date ."', '" . $icao . "' , " . (isset($value['inboud']) ? $value['inboud'] : 0) . ", " . (isset($value['outbound']) ? $value['outbound'] : 0) . ");";
}
//INSERT INTO flightsperhour(date, aerodrome, inbound,outbound) VALUES('2013091713', 'EBBR' , 0, 1);
//INSERT INTO flightsperhour(date, aerodrome, inbound,outbound) VALUES('2013091713', 'ELLX' , 0, 1);
if(mysql_query($sql))
{
} else{
die(mysql_error());
}
EDIT: Mysql error: 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 'INSERT INTO flightsperhour(date, aerodrome, inbound, outbound) VALUES('2013' at line 2
EDIT2: Fixed the single missing '
EDIT3: On request of the programming student a print_r of his solution
INSERT INTO flightsperhour(date, aerodrome, inbound, outbound)
VALUES('2013091713', 'EBBR' , '', '1'),
VALUES('2013091713', 'ELLX' , '', '1')
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 'VALUES('2013091713', 'ELLX' , '', '1')' at line 3