Jump to content

Unexpected $end....but where?


AdRock

Recommended Posts

I am getting the usual unexpected $end and can't see where it is.  I've checked all my curly braces so it can't be that

 

<?php  

require("includes/init.php"); 

// Select all the rows in the markers table

$query = "SELECT * FROM carshare WHERE 1";
$result = mysql_query($query);

if (!$result) {  
    die('Invalid query: ' . mysql_error());
} 

$num = mysql_num_rows($result);

if ($num != 0) {

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

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

    	while ($row = mysql_fetch_array($result)) {
	if ($row['start_street']) {
  	    		$_xml .='\t<marker address="'.$row['start_street'].'" postcode="'.$row['start_postcode'].'";
    		$_xml .=" lat="'.$row['start_lat'].'" lng="'.$row['start_long'].'" type="'.$row['start_type'].'">";
    		$_xml .="\t</marker>\r\n";
    		} 
    		else {
    		$_xml .="\t<marker_address=\"Nothing Returned\">\r\n";
	    		$_xml .="\t</marker>\r\n";
		}
    	}
    	$_xml .="</markers>";

    	fwrite($file, $_xml);
    	fclose($file);

    	echo "XML has been written.  <a href=\"results.xml\">View the XML.</a>";
}
else {
    	echo "No Records found";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/98154-unexpected-endbut-where/
Share on other sites

Look closely at these lines you posted:

$_xml .='\t<marker address="'.$row['start_street'].'" postcode="'.$row['start_postcode'].'";
$_xml .=" lat="'.$row['start_lat'].'" lng="'.$row['start_long'].'" type="'.$row['start_type'].'">";
$_xml .="\t</marker>\r\n";

 

Your quotes are off, and they could well be causing issues. Try this instead:

<?php
$_xml .= "\t<marker address=\"{$row['start_street']}\" postcode=\"{$row['start_postcode']}";
$_xml .= " lat=\"{$row['start_lat']}\" lng=\"{$row['start_long']}\" type=\"{$row['start_type']}\">";
$_xml .= "\t</marker>\r\n";
?>

 

Check the rest of your strings, too, just to make sure your quotes aren't off like these were.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.