0

我不知道发生了什么,我一遍又一遍地检查了我在 PHP 和 Javascript 中的代码,但找不到任何额外的 },它没有对应的 {,谁能帮我看看代码?

这是PHP文件,加载函数可以成功加载,但是,当我单击“查看日志”按钮时,出现上述消息。

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 "<select id='option'>";
    print "<option value='3'>Tech</option>";
    print "<option value='4'>Client</option>";
    print "</select>";
    print "<input type='button' value='View the log' onclick='viewlog(document.getElementById('option').value)'/>";
    print "<br>";

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

function viewlog($DB, $sort){
    print "<h1>repeat</h1>";
    $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<br>";
    print "<table><th><td>Tech</td><td>Client</td><td>Site</td>";
    print "<td>Date and Time</td><td>Type</td></th>";
    while($row = mysql_fetch_array($result)){
        print "<tr><td>".$row['TechName']."</td>";
        print "<td>".$row['ClientName']."</td>";
        print "<td>".$row['SiteName']."</td>";
        print "<td>".$row['Time']."</td>";
        print "<td>".$row['Type']."</td></tr>";
        }
    print "</table>";
}

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);

下面是 Javascript 代码:

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 && 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 && xmlhttp.status == 200){
        document.getElementById("View").innerHTML=xmlhttp.responseText;         
    }
}
xmlhttp.open("GET","back.php?function="+num, true);
xmlhttp.send();
}

我试图隐藏 js 文件中的 viewlog 函数,也隐藏 PHP 文件的 viewlog 函数中的内容,但是两个动作仍然发出相同的消息,我真的不知道如何调试它。有人可以帮帮我吗?

4

1 回答 1

2

我认为浏览器会在你使用与 javascript 字符串相同的属性引号时遇到问题(你在两者中都这样做,但我只举一个例子):

onclick='viewlog(document.getElementById('option').value)'

进入

onclick='viewlog(document.getElementById(&quot;option&quot;).value)'
于 2012-07-14T02:33:01.720 回答