0

我正在尝试读取 .CSV 文件并以 HTML 表格格式打印。页面末尾是一个评论文本字段,评论被提交并保存在数据库中。

当我在本地测试下面的代码时,它工作正常。当我尝试在 linux 服务器上运行它时,它在第一次打开时打印得很好,但是当我按下提交保存评论时,页面刷新并且表格不打印。给出“为 foreach() 提供的参数无效”错误。(注意:这不会在本地发生,我可以提交所有我想要的并且它不会返回错误。)

我在stackoverflow上进行了搜索,似乎大多数这些问题都与将变量声明为数组有关。但是,这对我来说似乎很奇怪,因为代码第一次运行良好,没有错误,但是一旦我提交它就会返回错误。

更新:下面发布的文件的完整代码。

<script>
    window.onunload = refreshParent;
    function refreshParent() {
        window.opener.location.reload();
    }
</script>

<?php
//---------------------------------Head/BG---------------------------------------
//Request Case ID
$case = "";
if(isset($_REQUEST['case'])) {
$case = $_REQUEST['case'];
}

$patientID = "";
if(isset($_REQUEST['patient'])) {
$patientID = $_REQUEST['patient'];
}


//Include basic functions to allow connection to SQL db.
include("generic.php"); 
//Include css and header information.
$printTitle = "Volume Report for Case ".$case."";
$printHeader = "Volume Report for Case ".$case."";
$printFooter = "";
$printBreadcrumb = "";
include("header.php");

//submit tableStatus update
if(isset($_REQUEST['submit'])) {
    saveTableStatus($case); 
}
//-----------------------------Start of Content----------------------------------

showStatusComment($case);
printVolumeTable($case,$patientID);
tableStatus($case);


//---------------------------End of Content--------------------------------------
//---------------------------Functions Definitions-------------------------------

//print report.csv Table
function printVolumeTable($case,$patientID){
echo "<html><body><table border='1'>\n\n";
$f = fopen("analyze/".$case."/".$patientID."/report.csv", "r");
while (($line = fgetcsv($f)) !== false) {
        echo "<tr>";

        foreach ($line as $cell) {
                echo "<td>" . htmlspecialchars($cell) . "</td>";
        }
        echo "<tr>\n";
}
fclose($f);
echo "\n</table></body></html>";
}


function showStatusComment($case) {

    $connection = getMySqlConnection();
    $sql = "SELECT p.STATUS_NAME, c.volume_comments FROM cases c, primary_status_lookup as p WHERE c.volume_status=p.STATUS_ID and c.caseid='".$case."'";
    $result = mysql_query($sql, $connection) or die(mysql_error());

    if($result!== FALSE){
        while ($record = mysql_fetch_row($result)) {
            $status=$record[0];
            $comments=$record[1];

            if($status == 'Clear Status') {$status = 'None'; $comments = 'None';}
            print("<p><b>Table Status: </b>".$status." / <b>Comments: </b>".$comments."</p>");
        }

    }
}

//Status & Comments 
function tableStatus($case) {
    $connection = getMySqlConnection();
    $sql = "SELECT volume_status, volume_comments FROM cases WHERE caseid='".$case."'";
    $result = mysql_query($sql, $connection) or die(mysql_error());

    if($result!== FALSE){
        while ($record = mysql_fetch_row($result)) {
            $status=$record[0];
            $comments=$record[1];

        print("<form><p>");

        showStatusComment($case);
        statusDropdown($case,$status);
        print("<input type=hidden name='case' value='".$case."'/>");
        print("&nbsp;&nbsp;&nbsp;<label><b>Comments:</b><textarea name='comments' cols=70 rows=2 >".$comments."</textarea></label><br/><br/>");
        print("<input type='submit' name='submit' value='Submit'/><INPUT type='button' value='Close Window' onClick='window.close()'></form>");


        }
    }

}


//Status Dropdown
function statusDropdown($case,$status){
    print("<b>Status:</b>");
    $dropdown = "<select name = 'status'><option selected='selected' value=NULL>--Select Status--</option>";

    $connection = getMySqlConnection();
    $sql = "SELECT STATUS_ID, STATUS_NAME FROM primary_status_lookup ORDER BY STATUS_ID ASC"; 
    $result = mysql_query($sql, $connection) or die(mysql_error());

    while($record=mysql_fetch_array($result)){

            if ($status == '') {

            $dropdown .= "<option value = '{$record['STATUS_ID']}'> {$record['STATUS_NAME']}</option>";

            } else if (($status == $record['STATUS_ID']) && ($status == '99')) { 

            $dropdown .= "<option value = '{$record['STATUS_ID']}'> {$record['STATUS_NAME']}</option>";

            } else if ($status == $record['STATUS_ID']) { 

            $dropdown .= "<option value = '{$record['STATUS_ID']}' selected='selected'> {$record['STATUS_NAME']}</option>";

            } else {

            $dropdown .= "<option value = '{$record['STATUS_ID']}'> {$record['STATUS_NAME']}</option>";

            }
    }
    $dropdown .="</select>";
    echo $dropdown;

}



function saveTableStatus($case)
{
    //retrieve selected status
    $status = '';
    if(isset($_REQUEST['status'])) {
        $status = $_REQUEST['status'];
    }

    //retrieve typed comments
    if(isset($_REQUEST['comments'])) {
        $comments = $_REQUEST['comments'];
    }

    if($status=='NULL') {
        print("<p class='error'>No status selected, please select a status and try again.</p>");
    }

    else if (($status!=='NULL')){
        $connection = getMySqlConnection();
        mysql_query("START TRANSACTION", $connection);

        if ($status =='99') {$comments = '';}
        $result= mysql_query("Update cases Set volume_status=".$status.", volume_comments ='".mysql_real_escape_string($comments)."' Where caseid='".mysql_real_escape_string($case)."'", $connection);
            if($result) {
                mysql_query("COMMIT", $connection);
                print("<p class='saved'>Table Status Updated!</p>");
            } else {
                mysql_query("ROLLBACK", $connection);
            }
            mysql_close($connection);

        }
}


?>
4

1 回答 1

0

如果您形成,并且采用张贴形式的脚本不在同一路径上,那么您的

 $f = fopen("analyze/".$case."/".$patientID."/report.csv", "r");

不会打开同一个文件。

编辑 -

好的,我认为您的问题是您的 $case 变量。如果没有请求,则 $case 为空白 ("")。所以上面的行将打开“analyze///report.csv”正如你所看到的,取决于这段代码

$case = "";
if(isset($_REQUEST['case'])) {
$case = $_REQUEST['case'];
}
于 2013-05-30T18:31:15.403 回答