2017-08-24 9 views
0

今週1週間以来私はこのエラーに悩まされています。私はグーグルで、Stackoverflowのものを含むすべての可能な解決策を試しました。これは私のコードです:XML出力の確認

<?php 
require("phpsqlsearch_dbinfo.php"); 
// Get parameters from URL 
$center_lat = $_GET["lat"]; 
$center_lng = $_GET["lng"]; 
$radius = $_GET["radius"]; 
// Start XML file, create parent node 
$dom = new DOMDocument("1.0"); 
$node = $dom->createElement("markers"); 
$parnode = $dom->appendChild($node); 
// Opens a connection to a mySQL server 
$connection=mysqli_connect ("localhost", $username, $password); 
if (!$connection) { 
    die("Not connected : " . mysqli_error()); 
} 
// Set the active mySQL database 
$db_selected = mysqli_select_db($connection, $database); 
if (!$db_selected) { 
    die ("Can\'t use db : " . mysqli_error($connection)); 
} 
// Search the rows in the markers table 
$query = sprintf("SELECT id, name, address, lat, lng, (3959 * acos(cos( 
    radians('%s')) * cos(radians(lat)) * cos(radians(lng) - 
    radians('%s')) + sin(radians('%s')) * sin(radians(lat)))) AS 
    distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 
    20", 
    mysqli_real_escape_string($connection, $center_lat), 
    mysqli_real_escape_string($connection, $center_lng), 
    mysqli_real_escape_string($connection, $center_lat), 
    mysqli_real_escape_string($connection, $radius)); 
$result = mysqli_query($connection, $query); 
$result = mysqli_query($connection, $query); 
if (!$result) { 
    die("Invalid query: " . mysqli_error($connection)); 
} 
header("Content-type: text/xml"); 
// Iterate through the rows, adding XML nodes for each 
while ($row = @mysqli_fetch_assoc($result)){ 
    $node = $dom->createElement("marker"); 
    $newnode = $parnode->appendChild($node); 
    $newnode->setAttribute("id", $row['id']); 
    $newnode->setAttribute("name", $row['name']); 
    $newnode->setAttribute("address", $row['address']); 
    $newnode->setAttribute("lat", $row['lat']); 
    $newnode->setAttribute("lng", $row['lng']); 
    $newnode->setAttribute("distance", $row['distance']); 
} 
echo $dom->saveXML(); 
?> 

私の目標は、それが働いていることを確認するために、ブラウザに出力するためにXMLであるが、私はこれらのエラーを取得されています。詳細については

enter image description here 参照:https://developers.google.com/maps/solutions/store-locator/clothing-store-locator ができ誰かが私を助ける???

+0

コードを正しくインデントする必要があります。誰もがあなたのコードを読むのに役立ち、それはあなたにとっても良いことです。 – ryantxr

+2

XML出力を貼り付けることはできますか?それはブラウザのメッセージで、PHP error_logメッセージではありません。 – delboy1978uk

+0

@ delboy1978uk私のXML出力は添付の画像です – sankareb

答えて

-1

これはブラウザのメッセージであり、PHPのerror_logメッセージではありません。

XMLの前に何かが出力されています。おそらくPHPの警告または通知。そのゴミを抑える!

最高のエラーログを記録するには、error_reportingを-1に設定し、display_errorsをオフにして、カスタムerror_logを設定します。次に、端末でtail -f /path/to/error_logと入力します。 Webページの表示を乱すことなく、通知、警告、エラーがリアルタイムでスクロールします。

+0

努力をいただきありがとうございます!しかし、私はcdlインターフェイスを使用していない、私はむしろxamppからphpmyadminを使用して、エディタとして昇華! – sankareb

+0

私はあなたが言ったことをしましたが、別のエラーが発生しました: 未定義のインデックス:C:\ xampp \ htdocs \ storelocator.php on line 5 未定義のインデックス:C:\ xampp \ htdocs \ storelocator.phpの行番号6 – sankareb

+0

これは$ _GET ["lat"]が設定されていないことを意味します。 $ _POSTを意味していないと確信していますか? GET varはhttp://blah.com/my/url?getvar=valueのようなURLにあります – delboy1978uk

0

実際に問題を解決するには十分ではありません。あなたはあなたがあなたが期待している入力を得ていることを確認するために以下を使用することができます。 XMLで

$required = ['lat', 'lng']; 
$missing = array_diff($required, $_GET); 
if (! empty($missing)) { 
    $missingString = implode(',', $missing); 
    die("missing {$missingString}"); 
} 

、開口部

<?xmlのバージョン= "1.0" エンコード= "UTF-8"?>

は、その前にスペースを持つことはできません。エコーがXMLを出力する前に、あなたのPHPコードがどこかにスペースを出力しています。

+0

私はこれを私のコードの先頭に置いています。これは私がブラウザに表示している出力です: ** missing * * ** lat **、** lng ** もし私がそれを削除したら、私は得ます: **未定義のインデックス:C:\ xampp \ htdocs \ storelocator.php 5行目のラット** – sankareb

+0

$ _GETそれが含まれていると思うものは含まれていません。ページへのアクセス方法を確認してください。 – ryantxr

+0

!私はすべてのことを試みましたが、まだ解決策はありませんでした!もしあなたが私を助けてくれたら!これは次のチュートリアルです:https://developers.google.com/maps/solutions/store-locator/clothing-store-locator – sankareb

関連する問題