Mattlinux1
Mattlinux1

Reputation: 807

PHP output to XML with a while loop error

I Get the error: error on line 1 at column 390: Opening and ending tag mismatch: genre line 0 and songs.

<?php
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='ISO-8859-1'?>";
echo "<songs>";
$sr = $_GET["sr"];
$conn = new PDO("mysql:host=localhost;dbname=xxxxx;","xxxxx","xxxxx");
$songresults = $conn->query("SELECT * FROM `smashhits` WHERE artist LIKE'%$sr%'");
while($row=$songresults->fetch())
{
echo "<id> ID: $row[ID] </id>";
echo "<song> Song: $row[song] </song>";
echo "<artist> Artist: $row[artist] </artist>";
echo "<year> Year: $row[year] </year>";
echo "<genre> Genre: $row[genre] <genre>";
echo "<quantity> Quantity: $row[quantity] </quantity>";
}
echo "</songs>"
?>

I would be thankful for anyone who knows what's going wrong with the code above.

Upvotes: 0

Views: 48

Answers (1)

i alarmed alien
i alarmed alien

Reputation: 9530

Simple error:

echo "<genre> Genre: $row[genre] <genre>";

You've opened two genre tags. I'm sure you don't need me to tell you that it should be

echo "<genre> Genre: $row[genre] </genre>";

Upvotes: 2

Related Questions