troubleshooting Question

error on line 3 at column 1: Extra content at the end of the document - XML

Avatar of jun lastmo
jun lastmo asked on
PHPXML
1 Comment1 Solution834 ViewsLast Modified:
<?php
include "config.php";
if( ! ini_get('date.timezone') ){
    date_default_timezone_set('GMT');
}

/* require the user as the parameter */
if(isset($_GET['country'])) {
	
	/* soak in the passed variable or set our own */
	//$number_of_posts = isset($_GET['num']) ? intval($_GET['num']) : 10; //10 is the default
	$format = strtolower($_GET['format']) == 'json' ? 'json' : 'xml'; //xml is the default
	//$user_id = intval($_GET['user']); //no default

	$country = $_GET['country'];
	//$LastSyncDate = "2015-03-05 17:00:00.000";

	/* connect to the db */
	// $link = odbc_connect ('dms_production','sysprogress','sysprogress') or die('Cannot connect to ODBC data source.');
	
	/* grab the posts from the db */
	$query = "SELECT * FROM customers WHERE country='$country'";
					  
	$query = trim($query);
	$result =mysqli_query($con,$query);

	/* create one master array of the records */
	$table = array();
	if(mysqli_num_rows($result)) {
		while($record = mysqli_fetch_array($result)) {
			
			$table[] = array('record' => $record);
		    //echo array('record' => $record);

			//query for reservation details


			// $reservationdetails = "SELECT * FROM pub.sadtl WHERE id_sahdr = '".$record['id_sahdr']."'";	
			
			// $detailsresult = odbc_exec($link, TRIM($reservationdetails)) or die('Query error:  '.TRIM($reservationdetails));
			// if(odbc_num_rows($detailsresult)){
			// 	while($res = odbc_fetch_array($detailsresult)){
			// 		$table[] = array('record' => $record, 'details' => $res);
			// 	}
			
			
		}
	}

	/* output in necessary format */
	if($format == 'json') {
		header('Content-type: application/json');
		//echo json_encode($table);
		echo json_encode($table);
	}
	else {
		header('Content-type: text/xml');
		echo '<table>';
		foreach($table as $index => $record) {
			if(is_array($record)) { 
				foreach($record as $key => $value) {
					echo '<',$key,'>'."aferfwefawfawefa";
					if(is_array($value)) {
						foreach($value as $tag => $val) {
							echo '<',$tag,'>',htmlentities($val),'</',$tag,'>';
						}
					}
					echo '</',$key,'>';
				}
			}
		}
		echo '</table>';
	}

	/* disconnect from the db */
	@mysql_close($link);
}
else {
  echo '<h3>Error: No passed parameters.<br>';
        
}
?>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros