0

以下では、構文エラーが発生しています。SQL 構文にエラーがあります。MySQL サーバーのバージョンに対応するマニュアルを参照して、1 行目の「call, county, id, location, callcreated, station, units, calltype, lat, lng) VAL」の近くで使用する正しい構文を確認してください。理由がわかりません。どんな助けでも大歓迎です!

<?php

mysql_connect("localhost", "test", "test") or die(mysql_error());
mysql_select_db("firecom") or die(mysql_error());

$data = file_get_contents("http://208.71.205.35/PITS/");//thanks WCCCA!
$pattern = "/id=\"hidXMLID\" value=\"([^\"]+)\"/";//looking for the rnd xml id#
preg_match_all($pattern, $data, $xmlext);

$url = "http://208.71.205.35/PITS/xml/fire_data_" . $xmlext[1][0] . ".xml";//putting together the secret xml url
$xml = simplexml_load_file($url);

foreach ($xml->marker as $element) {

$lat = $element->attributes()->lat;
$lng = $element->attributes()->lng;
$countydirty = $element->AGENCY;// gets agency
$wcccanumberdirty = $element->CALL_NO;
$iddirty = $element->TWO_DIGIT_CALL_NO;// gets call id#
$calldirty = $element->CALL_TYPE_FINAL_D;// gets call type
$locationdirty = $element->LOCATION;// gets location
$callcreateddirty = $element->CALL_CREATED_DATE_TIME;
$stationdirty = $element->BEAT_OR_STATION;// get first marker station
$unitsdirty = $element->UNITS;// get first marker units
$calltypedirty = $element->TYPE; 

//this next section removes the "~" from the start of all the lines
$county = str_replace('~','',$countydirty);
$wcccanumber = str_replace('~','',$wcccanumberdirty);
$id = str_replace('~','',$iddirty);
$call = str_replace('~','',$calldirty);
$location = str_replace('~','',$locationdirty);
$callcreated = str_replace('~','',$callcreateddirty);
$station = str_replace('~','',$stationdirty);
$units = str_replace('~','',$unitsdirty);
$calltype = str_replace('~','',$calltypedirty);

mysql_query("INSERT INTO calls (wcccanumber, call, county, id, location, callcreated, station, units, calltype, lat, lng) VALUES('$wcccanumber', '$call', '$county', '$id', '$location', '$callcreated', '$station', '$units', '$calltype', '$lat', '$lng')") or die(mysql_error()); 

echo "$call - $county - $wcccanumber - $id - $location - $callcreated - $station - $units - $calltype <br />";
}

?>
4

3 に答える 3

5

call予約語です。バック ティックで囲む必要があります。

INSERT INTO calls (wcccanumber, `call`, ...
于 2012-12-10T20:21:38.480 に答える
2

callは mysql の予約語であるため、列名として使用する場合は、バックティックで引用する必要があります。

wcccanumber, `call`, county...

それとは別に、PDO / mysqli と準備済みステートメントに切り替えて、潜在的な SQL インジェクションの問題を修正する必要があります。

于 2012-12-10T20:21:46.390 に答える
1

call予約語です。バックティックで引用する必要があります:

mysql_query("INSERT INTO calls (wcccanumber, `call`, county, id, ...

PS データベースの問題 (特に構文エラー) の場合、その DOM のすべてを含める必要はありません。クエリの値を取得する方法は、ほとんど常に無関係です。

于 2012-12-10T20:21:51.197 に答える