0

Hi,

I'm getting:

Parse error: parse error in C:\wamp\www\Ajax\getcd.php on line 28.

(I have highlighted line 28 in red.)

for the following simple program that retrieves data from cd_catalog.xml file and displays in txthint div when user selects artist's name from select box.

does anyone know on what i'm doing wrong? thank you.

getcd.html

<script language="javascript" type="text/javascript">
function showCD(str){
    if (str=="")
        {
            document.getElementById("txtHint").innerHTML="";
            return;
        }
    if (window.XMLHttpRequest)
        xmlhttp=new XMLHttpRequest();
    else
        xmlhttp=new activeXObject("Microsoft.XMLHTTP");

    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText
    }

    xmlhttp.open("GET","getcd.php?q="+str,true);
    xmlhttp.send();
}
</script>

</head>

<body>
<form action="">
<select name="cds" onchange="showCD(this.value)">
<option value="">Select a CD</option>
<option value="Bob Dylan">Bob Dylan</option>
<option value="Bonnie Tyler">Bonnie Tyler</option>
<option value="Dolly Parton">Dolly Parton</option>
</select>
</form>
<div id="txtHint"><b>CD info will be listed here</b></div>
</body>
</html>

getcd.php

<?php
$q=$_GET['q'];

$xmlDoc=new DOMDocument();
$xmlDoc->load("cd_catalog.xml");

$x=$xmlDoc->getElementsByTagName('ARTIST');

for($i=0;$i<=$x->length-1;$i++)
    {
        //process only element nodes
        if ($x->item($i)->nodeType==1)
            {
                if ($x->item($i)->childNodes->item(0)->nodeValue==$q)
                    {
                        $y=($x->item($i)->parentNode);
                    }
            }
    }

$cd=($y->childNodes);

for($i=0;$i<$cd->length;$i++)
    {
        //process only element nodes
        if ($cd->item($i)->nodeType==1)
        {
            [COLOR="Red"]echo ("<b>".$cd->item($i)->nodeName.":</b>");[/COLOR]            echo ($cd->item($i)->childNodes->item(0)->nodeValue);
            echo ("<br/>");
        }
    }
?>

Edited by mike_2000_17: Fixed formatting

3
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by karthik_ppts
1

Try like this :

echo "<b>".$cd->item($i)->nodeName.":</b>";

or

$val=$cd->item($i)->nodeName;
echo "<b>".$val.":</b>";

Edited by Shanti C: n/a

Votes + Comments
0

Yes, you are right. It works fine now after removing the parentheses. thank you.

0

Always Post your code with code tags.
Mark this thread as solved if your problem solved.

how to mark this thread as solved?

0

Just below this post under the heading "Has this thread been answered?" click "Mark this Thread as Solved" link

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.