-2

I have the following PHP code. When I run it I get the error '*Parse error: syntax error, unexpected T_STRING in /home/ashb/public_html/databaseconnect.php on line 20'.*

When I had the code working, line 20 was: $xml_output .= "<?xml-stylesheet href=\"$xslt_file\" type=\"text/xsl\" ?>";

I need to change my code to $xml_output .= "<?xml-stylesheet href=\"$xslt_file\" type=\"text/css\" ?>";. Its after changing this that the error occurs.

What is wrong with it? The full code has been included below.

NOTE: The $xslt_file variable has been changed appropriately for the different lines of code above.

<?php 

header("Content-type: text/xml"); 

$host = "###"; 
$user = "###"; 
$pass = "###"; 
$database = "###"; 
$xslt_file = "/xmlstyle.css"; 
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); 
mysql_select_db($database, $linkID) or die("Could not find database."); 

$query = "SELECT * FROM users WHERE Username = 'Username4';";


$resultID = mysql_query($query, $linkID) or die("Data not found."); 

$xml_output = "<?xml version=\"1.0\"?>\n"; 
//$xml_output .= "<?xml-stylesheet href=\"$xslt_file\" type=\"text/xsl\" ?>";
$xml_output .= "<?xml-stylesheet href=\"$xslt_file\" type=\"text/css\" ?>";

$xml_output .= "<Users>\n"; 

for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ 
    $row = mysql_fetch_assoc($resultID); 
    $xml_output .= "\t<Person>\n"; 
    $xml_output .= "\t\t<Username>" . $row['username'] . "</Username>\n"; 
    $xml_output .= "\t\t<Firstname>" . $row['firstname'] . "</Firstname>\n"; 
    $xml_output .= "\t\t<Lastname>" . $row['lastname'] . "</Lastname>\n";
    $xml_output .= "\t\t<Title>" . $row['Title'] . "</Title>\n";
    $xml_output .= "\t\t<Description>" . $row['Description'] . "</Description>\n";  
    $xml_output .= "\t\t<Location>" . $row['Location'] . "</Location>\n";
    $xml_output .= "\t\t<Feeling>" . $row['Feeling'] . "</Feeling>\n";
        // Escaping illegal characters 
        $row['text'] = str_replace("&", "&", $row['text']); 
        $row['text'] = str_replace("<", "<", $row['text']); 
        $row['text'] = str_replace(">", "&gt;", $row['text']); 
        $row['text'] = str_replace("\"", "&quot;", $row['text']); 

    $xml_output .= "\t</Person>\n"; 
} 

$xml_output .= "</Users>"; 

echo $xml_output; 

?> 
googleyberry
  • 73
  • 3
  • 10

1 Answers1

1

The parsing of the line above the line throwing the error goes bananas.

//$xml_output .= "<?xml-stylesheet href=\"$xslt_file\" type=\"text/xsl\" ?>";

The comment isn't commenting out the final ?>";

Using an IDE like phpstorm/netbeans/zend/etc shows this right away.

JimL
  • 2,501
  • 1
  • 19
  • 19