Forum Moderators: coopster

Message Too Old, No Replies

Script Crashes in the Middle of XML generation

         

chornbeck

6:44 pm on May 10, 2006 (gmt 0)

10+ Year Member



I have a php script that generates an XML file for use in a Google Maps application. I'd say it works fine about 70% of the time, while the rest of the time, the script crashes in the middle of generating the XML.

I end up with XML that is incomplete and therefore makes the rest of the app no good...

Why would it work sometimes and not others? Why would it stop generating the XML, sometimes in the middle of a word?

Any help?

chornbeck

6:46 pm on May 10, 2006 (gmt 0)

10+ Year Member



Here's the script btw:

[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<?

if($_POST['submit'])

{

$dbh=mysql_connect ("localhost", "orlandoi_gmap", "gmap") or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db ("orlandoi_gmap");

$InputtedZIP = ($_POST['InputtedZIP']);

$inputCoords = mysql_query("Select LAT, LNG from coord_db where ZIP = $InputtedZIP") or die(mysql_error());

while($row = mysql_fetch_array($inputCoords))

{

?>

<tr>

<td><font color=#000000 face="arial">Map has been generated showing all ZIP Codes containing a Festiva Owner within a 50 mile radius of the ZIP code <?php echo $InputtedZIP;?></td>

</tr>

<?php

$inputLAT = $row['LAT'];

$inputLATMINUS = $inputLAT - .192;

$inputLATPLUS = $inputLAT + .192;

$inputLNG = $row['LNG'];

$inputLNGPLUS = $inputLNG + .164;

$inputLNGMINUS = $inputLNG - .164;

$availZIP = mysql_query("SELECT ZIP from coord_db WHERE (LAT BETWEEN $inputLATMINUS AND $inputLATPLUS) AND (LNG BETWEEN $inputLNGMINUS AND $inputLNGPLUS)") or die(mysql_error());

$_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";

$_xml .="<markers>\r\n";

while ($roo = mysql_fetch_array($availZIP)) {

$ZIPArr = $roo['ZIP'];

$ZIPQuery = mysql_query("SELECT ZIPCode, FirstName, LastName from owner_zips WHERE ZipCode = $ZIPArr") or die (mysql_error());

while ($rop = mysql_fetch_array($ZIPQuery)) {

$ownerrop = $rop['ZIPCode'];

$availCOORD = mysql_query("SELECT LAT,LNG from coord_db WHERE ZIP = $ownerrop") or die(mysql_error());

while ($rou = mysql_fetch_array($availCOORD)) {

if ($rou["LAT"]) {

$_xml .="\t<marker lat=\"" . $rou["LAT"] . "\" lng=\"" . $rou["LNG"] . "\" html=\"" . $rop['FirstName'] . " " . $rop["LastName"] . "\" label=\"" . $rop["ZIPCode"] . "\" />\r\n";

}

}

}

}

$_xml .="</markers>";

$file= fopen("results.xml", "w");

fwrite($file, $_xml);

fclose($file);

echo "<a href=\"gmapnames.php?LATCNT=$inputLAT&amp;LNGCNT=$inputLNG\">View the map!.</a>";
}
}

?>

chornbeck

12:50 pm on May 11, 2006 (gmt 0)

10+ Year Member



bump for any help?

coopster

2:12 pm on May 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, chornbeck.

the script crashes in the middle of generating the XML

What error message are you receiving? Have you turned up error_reporting() [php.net] so you can tell?

chornbeck

3:09 pm on May 11, 2006 (gmt 0)

10+ Year Member



I'm not receiving an error message. When the page appears that uses the XML, it doesn't display the proper markers.

The reason I know it's crashing, is that when I use the app and no markers are displayed, I look at the XML that was generated and I see that the file just stops, usually in the middle of a word. The incomplete file causes the error.

What I'm asking is if there's something that's wrong with my script that would cause the xml file generation to stop mid-stream?

coopster

6:45 pm on May 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I can't see anything off hand, except this:
$_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
If you have short_open_tag [php.net] on you might be causing yourself some issues.

chornbeck

12:48 pm on May 12, 2006 (gmt 0)

10+ Year Member



How can I tell if it's turned on or not?

coopster

2:57 pm on May 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



A quick and easy way to see all your directives is to run a phpinfo() [php.net] script.