Uncaught SyntaxError: Unexpected token }
<p>I dont know what is happening, I have double checked my code in PHP and Javascript again and again, but are not able to find any additional }, which does not have a corresponding {, can anyone help me to take a look of the code?</p>

<p>Here is the PHP file, the load function can successfully load, however, when I click the button "View the log", the above message occurs.</p>

<pre><code>function load($DB){
    $dbConnection = mysql_connect($DB['server'], $DB['loginName'], $DB['password']);
    if(!$dbConnection){
        die('Error! ' . mysql_error());
        }
    mysql_select_db($DB['database'], $dbConnection);
    $result = mysql_query("SELECT ClientName FROM Client");

    print "Sort by";
    print "&lt;select id='option'&gt;";
    print "&lt;option value='3'&gt;Tech&lt;/option&gt;";
    print "&lt;option value='4'&gt;Client&lt;/option&gt;";
    print "&lt;/select&gt;";
    print "&lt;input type='button' value='View the log' onclick='viewlog(document.getElementById('option').value)'/&gt;";
    print "&lt;br&gt;";

    print "Tech Name checked in/out from";
    print "&lt;select id='client'&gt;";
    while($row = mysql_fetch_array($result)){
        print "&lt;option value='".$row['ClientName']."'&gt;".$row['ClientName']."&lt;/option&gt;";
    }
    print "&lt;/select&gt;";
    print "&lt;input type='button' value='Display' onclick='display(document.getElementById('client').value)'/&gt;";
    print "&lt;br&gt;";
    print "&lt;button type='button' onclick='back.php?function=5'&gt;Export the log to .csv&lt;/button&gt;";
    print "&lt;br&gt;";
}

function viewlog($DB, $sort){
    print "&lt;h1&gt;repeat&lt;/h1&gt;";
    $dbConnection = mysql_connect($DB['server'], $DB['loginName'], $DB['password']);
    if(!$dbConnection){
        die('Error! ' . mysql_error());
        }
    mysql_select_db($DB['database'], $dbConnection);
    $query = "SELECT * 
                FROM Tech AS T, Client AS C, Site AS S, Log AS L 
                WHERE T.TechID=L.TechID AND C.ClientID=L.ClientID AND S.SiteID=L.SiteID ";
    if($sort=="Tech")
        $query .= "ORDER BY T.TechName ASC, L.Time DESC";
    else if($sort=="Client")
        $query .= "ORDER BY C.ClientName ASC, L.Time DESC";
    $result = mysql_query($query) or die('Error! ' . mysql_error());; 
    print "Real-Time check in/check out&lt;br&gt;";
    print "&lt;table&gt;&lt;th&gt;&lt;td&gt;Tech&lt;/td&gt;&lt;td&gt;Client&lt;/td&gt;&lt;td&gt;Site&lt;/td&gt;";
    print "&lt;td&gt;Date and Time&lt;/td&gt;&lt;td&gt;Type&lt;/td&gt;&lt;/th&gt;";
    while($row = mysql_fetch_array($result)){
        print "&lt;tr&gt;&lt;td&gt;".$row['TechName']."&lt;/td&gt;";
        print "&lt;td&gt;".$row['ClientName']."&lt;/td&gt;";
        print "&lt;td&gt;".$row['SiteName']."&lt;/td&gt;";
        print "&lt;td&gt;".$row['Time']."&lt;/td&gt;";
        print "&lt;td&gt;".$row['Type']."&lt;/td&gt;&lt;/tr&gt;";
        }
    print "&lt;/table&gt;";
}

function export($DB){
    $dbConnection = mysql_connect($DB['server'], $DB['loginName'], $DB['password']);
    if(!$dbConnection){
        die('Error! ' . mysql_error());
        }
    mysql_select_db($DB['database'], $dbConnection);
    $result = mysql_query("SELECT TechName, ClientName, SiteName, Time, Type
                            INTO OUTFILE 'result.csv'
                            FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED by '\"'
                            LINES TERMINATED BY '\n'
                            FROM Tech AS T, Client AS C, Site AS S, Log AS L
                            WHERE T.TechID=L.TechID AND C.ClientID=L.ClientID AND S.SiteID=L.SiteID
                            ORDER BY L.Time DESC");
    $Time = date('Y_m_d_H_i');
    $fileName = "Report_" + $Time;
    header('Content-type: text/csv'); 
    header('Content-Disposition: attachment; filename="'.$fileName.'.csv"'); 
    readfile('result.csv');
}

$function = $_GET['function'];
if($function==0)
    load($DB);
elseif($function==3)
    viewlog($DB, "Tech");
elseif($function==4)
    viewlog($DB, "Client");
elseif($function==5)
    export($DB);
</code></pre>

<p>Below is the Javascript code:</p>

<pre><code>function load(){
var xmlhttp;
if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
}else{ // code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}               

xmlhttp.onreadystatechange = function(){
    //document.getElementById("action").innerHTML=xmlhttp.status;
    if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200){
        document.getElementById("action").innerHTML=xmlhttp.responseText;       
    }
}
var num = 0;
xmlhttp.open("GET","back.php?function="+num, true);
xmlhttp.send();
}

function viewlog(num){
var xmlhttp;
if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
}else{ // code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}               

xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200){
        document.getElementById("View").innerHTML=xmlhttp.responseText;         
    }
}
xmlhttp.open("GET","back.php?function="+num, true);
xmlhttp.send();
}
</code></pre>

<p>I have tried to hide the viewlog function in js file, also for the content in viewlog function of PHP file also, but both actions still give out the same message, I really have no idea how to debug it. Can someone give me a hand?</p>
