XML Parsing Error: No Element Found


#1

So im getting this error when I try to run a script I know should work:

XML Parsing Error: no element found
Location: http://www.goodshepherdfw.org/v20/calendar/calendar.php
Line Number 1, Column 1:

^

When I run it on my own server, it runs fine. But I'm putting the script on my clients web host, (hostway), and this is the message that comes up..

Here's what the calendar.php file looks like:

<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-Type: text/xml; charset=utf-8");

//////////////////////////////////////
// set these variables for your MySQL
$dbhost = 'dbhost';	// usually localhost
$dbuser = 'user';		// database username
$dbpass = 'password';		// database password
$database = 'databaseName';		// database
//////////////////////////////////////

$db = @mysqli_connect($dbhost, $dbuser, $dbpass, $database) or die ("<?xml version=\\"1.0\\" ?><response><content><![CDATA[<span class='error'>Database connection failed.</span>]]></content></response>");


$xml = '<?xml version="1.0" ?><response><content><![CDATA[';


then the code still goes on and on for awhile.

but is this something todo with Hostways php setup? How would I go about changing this?

here's the link to the web site with the error showing:
http://www.goodshepherdfw.org/v20/calendar/calendar.php

Thanks!


#2

I don't see an error, and post all of the code.

[edit] Oh, this isn't a PHP error, it's an XML error

One sec.


#3

I still see the message when I look at it...

here's the link for what the page should look like:
http://projects.mattvanblari.com/calendarTest.php

here's the code

<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); 
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" ); 
header("Cache-Control: no-cache, must-revalidate" ); 
header("Pragma: no-cache" );
header("Content-Type: text/xml; charset=utf-8");

//////////////////////////////////////
// set these variables for your MySQL
$dbhost = 'dbhost';    // usually localhost
$dbuser = 'user';        // database username
$dbpass = 'password';        // database password
$database = 'databaseName';        // database
//////////////////////////////////////

$db = @mysqli_connect($dbhost, $dbuser, $dbpass, $database) or die ("<?xml version=\\"1.0\\" ?><response><content><![CDATA[<span class='error'>Database connection failed.</span>]]></content></response>");


$xml = '<?xml version="1.0" ?><response><content><![CDATA[';
	$month = $_GET['month'];
	$year = $_GET['year'];
		
	if($month == '' && $year == '') { 
		$time = time();
		$month = date('n',$time);
	    $year = date('Y',$time);
	}
	
	$date = getdate(mktime(0,0,0,$month,1,$year));
	$today = getdate();
	$hours = $today['hours'];
	$mins = $today['minutes'];
	$secs = $today['seconds'];
	
	if(strlen($hours)<2) $hours="0".$hours;
	if(strlen($mins)<2) $mins="0".$mins;
	if(strlen($secs)<2) $secs="0".$secs;
	
	$days=date("t",mktime(0,0,0,$month,1,$year));
	$start = $date['wday']+1;
	$name = $date['month'];
	$year2 = $date['year'];
	$offset = $days + $start - 1;
	 
	if($month==12) { 
		$next=1; 
		$nexty=$year + 1; 
	} else { 
		$next=$month + 1; 
		$nexty=$year; 
	}
	
	if($month==1) { 
		$prev=12; 
		$prevy=$year - 1; 
	} else { 
		$prev=$month - 1; 
		$prevy=$year; 
	}
	
	if($offset <= 28) $weeks=28; 
	elseif($offset > 35) $weeks = 42; 
	else $weeks = 35; 
	
	$xml .= "<div id='left'>
				 <table class='calHead'>
						<tr>
							<td class='date'>
									$name $year2

							</td>
						</tr>
						<tr>
							<td class='calNav'>
								  <input type='button' onClick='navigate($prev,$prevy,\\"\\")' value='Last' />
								  <input type='button' onClick='navigate(\\"\\",\\"\\",\\"\\")' value='Current' />
								  <input type='button' onClick='navigate($next,$nexty,\\"\\")' value='Next' />
								  <input type='button' onClick='showJump(this)' value='Jump To:' />
 							</td>
						</tr>
				</table>
				<table class='cal'>
					<tr class='dayhead'>
						<td>Sun</td>
						<td>Mon</td>
						<td>Tue</td>
						<td>Wed</td>
						<td>Thu</td>
						<td>Fri</td>
						<td>Sat</td>
					</tr>";
	
	$col=1;
	$cur=1;
	$next=0;
	
	for($i=1;$i<=$weeks;$i++) { 
		if($next==3) $next=0;
		if($col==1) $xml.="\
<tr class='dayrow'>"; 
	  	
		$xml.="\	<td onMouseOver=\\"this.className='dayover'\\" onMouseOut=\\"this.className='dayout'\\">";
	
		if($i <= ($days+($start-1)) && $i >= $start) 
		{
			$xml.="<p";
	
			if(($cur==$today[mday]) && ($name==$today[month]) && ($year2==$today[year])) 
			{
				$xml.=" class='currDay'";
			}
			
				$xml.=">$cur";
			
			$sql = "SELECT  eventCal_occ.eventID, eventCal_info.eventID, eventCal_occ.date, eventCal_occ.startTime FROM eventCal_info, eventCal_occ WHERE eventCal_occ.date ='$year-$month-$cur'AND eventCal_occ.eventID = eventCal_info.eventID";
			$result =  mysqli_query($db, $sql);
			
			$events = mysqli_num_rows($result);
			 if( mysqli_num_rows($result) > 0) 
			{
				$row =  mysqli_fetch_row($result);
				$xml.="<a href='javascript:navigate($month,$year,\\"".$row[2]."\\")'>$events Event(s)</a>";			
			}
			
			$xml.="\
\	</p></td>\
";
	
			$cur++; 
			$col++; 
			
		} 
		else 
		{ 
			$xml.="&nbsp;\
\	</td>\
"; 
			$col++; 
		}  
		    
	    if($col==8) 
		{ 
		    $xml.="\
</tr>\
"; 
		    $col=1; 
	    }
	}
	
	$xml.="</table></div>";
	  
if($_GET['event'] != '') 
{
	$xml .= "<div id='eventDetails'>";
	$fields = explode("-",$_GET['event']);
	$sql = "SELECT dateID, eventCal_occ.eventID, eventName, DATE_FORMAT(date, '&#37;m/%d/%Y') AS date, description, eventType, contactName, contactEmail, contactPhone, DATE_FORMAT(startTime,'%l:%i') AS startTime, DATE_FORMAT(endTime,'%l:%i%p') AS endTime FROM eventCal_occ, eventCal_info WHERE date = '".$_GET['event']."' AND eventCal_occ.eventID = eventCal_info.eventID";
	$result = mysqli_query($db, $sql);
	
	
	while($row =  mysqli_fetch_array($result)) 
	{
			$xml .= "<div id='event'>";
			$xml .= "<div class='heading'>";
				$xml .= "<div><p class='back'><a href='javascript:navigate($month,$year,\\"\\")'>Close Event(s)</a></p></div>";
				$xml .= "<div><p class='title'>".$row['eventName']."</p></div>";
				$xml .= "<div><p class='posted'>".$row['date']." ".$row['startTime']." - ".$row['endTime']."</p></div>";
			$xml .= "</div>";//end heading div
			$xml .= "<div><p class='description'>".$row['description']."</p></div>";
			$xml .="<div><p class='contactInfo'>For more information, please contact ".$row['contactName']." at ".$row['contactEmail'].", or ".$row['contactPhone']."</p></div>";
			$xml .= "</div>";//end EVENT div
	}
	$xml .="</div>";
	
}
	
$xml .= "]]></content></response>";
echo $xml;

?>


#4

er... try not rendering as an xml document but plain text and you'll be able to see if there is a formatting error in the xml to adequately debug it.


#5

Double check your file at http://www.goodshepherdfw.org/v20/calendar/calendar.php.

Right now nothing is being sent for the request, that is the reason for the error. A blank document is not valid XML.


#6

@imaginethis: When I try taking out the headers, all the page shows is a blank document, which isn't what it should be doing. It should end up like this:
http://projects.mattvanblari.com/calendarTest.php

but for some reason it ends up like this...

http://www.goodshepherdfw.org/v20/calendar/calendar.php

@bhanson: If it isn't valid XML then why is it showing up on the other page with the exact same code(except for the database information)?


#7

I'm saying, your page is not outputting anything, and a blank document is not valid XML.

Try putting this at the very top of your file and see if it shows up:

echo "Test";
exit();

#8

the code shows up fine


#9

Now put it right below the headers and try.


#10

okay, now I get the error:

XML Parsing Error: syntax error
Location: http://www.goodshepherdfw.org/v20/calendar/calendar.php
Line Number 1, Column 1:

Test
^

so why isn't the rest of the code outputting? and why is the error being said it's found on colum 1, line 1?


#11

It's a client side parsing error, not a server side error. The first thing that is sent to the browser when you put that statement there is "Test", and "Test" is invalid XML so that's why it's showing it on line 1.

I'm not sure why the rest isn't being displayed, but something is preventing you from sending the rest of the content to the browser.

Make a copy of the file and start pruning it down until it starts to work again.


#12

but I still don't understand why it's working on my host, and not my clients.

can the host settings have anything todo with it?


#13

the clients host has PHP 4.2 on it...

would that have anything to do with it?


#14

I changed all my "msqli" to "mysql" and it works fine now...

thanks for all your help;

smile


#15