Parse error: syntax error, unexpected ';', expecting ']' in C:\xampp\htdocs\eazyR\eazy\sites\erp\ajaxify\excel.php on line 37

Parse error: syntax error, unexpected ';', expecting ']' in C:\xampp\htdocs\eazyR\eazy\sites\erp\ajaxify\excel.php on line 37

请帮助...正在处理 html 页面中的表格,将我的 SQL table 导出到 excel 并下载。但我一直遇到错误

每次我单击“导出到 excel”按钮时,它总是将我带到一个新页面,而不是将数据导出到 excel。 下面是我的表格和 excel.php 脚本

表格

<form method="post" action="sites/erp/ajaxify/excel.php">
    <div id="content">
        <div class="col-md-4 col-md-offset-4 text-center">
                <div class="form-group">
                    <button id="exportbtn" class="btn btn-lg btn-success btn-block">  Export to Excel </button>
                </div>  
        </div>
    </div>
</form>

和Excel.php

if(isset($_REQUEST['tablename']) && isset($_REQUEST['keyy'])){
$tablename = use_if_sent('tablename');
$result = $ez_db->query("SELECT `firstname`, 'lastname', 'email', 'gender', 'user_group', 'phone', status' FROM 'signup'");
 if(mysql_num_rows($result) > 0)
{
        $output .= '
        <table class="table" bordered="1">  
            <tr>  
                <th>First name</th>
                <th>Lastname</th>
                <th>Email</th>
                <th>Gender</th>
                <th>Department</th>
                <th>Phone</th>
                <th>Status</th>
            </tr>
        ';
        while($row = mysql_fetch_array($result))
        {
           $output .= '
            <tr>  
                <td>'.$row["firstname".'</td>  
                <td>'.$row["lastname"].'</td>  
                <td>'.$row["email"].'</td>  
                <td>'.$row["gender"].'</td>  
                <td>'.$row["user_group"].'</td>
                <td>'.$row["phone"].'</td>
                <td>'.$row["status"].'</td>
            </tr>
           ';
        }
      $output .= '</table>';
      header('Content-Type: application/xls');
      header('Content-Disposition: attachment; filename=download.xls');
      echo $output;
    }  
}
?>

请更正此代码:

<td>'.$row["firstname".'</td> 

对此:

<td>'.$row["firstname"].'</td>

在Excel.php

<td>'.$row["firstname".'</td> 

应更改为

<td>'.$row["firstname"].'</td> 

您错过了关闭方括号 ]。

并且您没有在此处进行 excel 导出。您正在将内容类型设置为 application\xls 到 html 内容。这不会导出 excel。

请参阅 Excel export tutorial 以了解 excel 导出。

将您的 html 代码更改为此。

    <form method="post" action="sites/erp/ajaxify/excel.php" target="exportExcelFrame">
    <div id="content">
        <div class="col-md-4 col-md-offset-4 text-center">
                <div class="form-group">
                    <button id="exportbtn" class="btn btn-lg btn-success btn-block">  Export to Excel </button>
                </div>  
        </div>
    </div>
</form>
<iframe style="display:none;" id="exportExcelFrame" name="exportExcelFrame"></iframe>