0

我有带有 2 个日期文本字段区域和 2 个按钮的 html 表单,它根据日期间隔向用户提供不同的报告。起初还可以,但是我将今天的时间设置为 textfields 它发疯了。我将日期分配给会话,以便其他 report.php 文件在那里查询 sql。我知道这太容易了,但我看不出这里有什么问题。它没有给出正确的结果。

我的索引页面形式如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1254">
<?
    include "head.inc";
    include("lib/config.php");
    include("lib/oracle.php");
    include("lib/smarty/Smarty.class.php");
    include("lib/tcpdf/tcpdf.php");
?>
<?php
     $db=new OracleDB();

     $d1=date('d/m/Y');
     $d2=date('d/m/Y');


?>
<title>Reports</title>
</head>
<script type="text/javascript">
         $(document).ready(function() {
            $("#DATE1").datepicker();
            $("#DATE2").datepicker(); 
        });

        function Report()
        {
            if($('#DATE1').val()=='' || $('#DATE2').val()=='')
            {
                 alert('Fill the dates');
                 return false;
            }
            else
            {
                window.open('report2.php');
            }
        }
        function Report_Group()
        {
            if($('#GIR_TAR').val()=='' || $('#BIT_TAR').val()=='')
            {
                 alert('Fill the dates');
                 return false;
            }
            else
            {
                window.open('report1.php');
            }
        }
</script>

<body>
<form name="FORM" action="report_index.php" method="post"> 
<table class="bordered" align="center">
<tr><th colspan="4" align="center"><b>Reports</b></th></tr>
<tr>
<td>date1:</td><td><input name="DATE1" id="DATE1" type="text" value="<?echo $d1;?>" /></td><td>date2:</td><td colspan="2"><input name="DATE2" id="DATE2" type="text" value="<?echo $d2;?>" /></td>
</tr>
<tr>
<th align="right" colspan="2" ><input type="submit" name="REPORT1" id="REPORT1" value="" class="INPUT_BUTTON" onclick="return Report_Group();"/></th><th colspan="3"><input type="submit" name="REPORT2" id="REPORT2" value="" class="INPUT_BUTTON" onClick="return Report();"/></th>
</tr>
</table></form>
</body>
</html>
<?php
     $db=new OracleDB();

     session_start();

     if (isset($_POST["REPORT1"])||isset($_POST["REPORT2"]))
     {
         $_SESSION["DATE1"]=$_POST["DATE1"];
         $_SESSION["DATE2"]=$_POST["DATE2"];
     }

?>

谢谢你的时间!

报告索引.php:

<?php
    session_start();
    $ret=false;  

    include("../lib/config.php");
    include("../lib/oracle.php");
    include("../lib/smarty/Smarty.class.php");
    include("../lib/tcpdf/tcpdf.php");

    //header('Content-Type: text/html; charset=WINDOWS-1254');


function Rapor_View($Title,$FileName)
{
    $tpl=new Smarty();
    $tpl->assign("TITLE",$Title);
    $tpl->assign("FILE",$FileName);
    $tpl->display("../tpl/rapor_pdf.tpl.html");
}

function Rapor_Pdf($Baslik,$FileName,$Html,$Page="A4",$Land="P")
{
    $pdf = new TCPDF('L', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetKeywords('');
    $pdf->setPrintHeader(true);
    $pdf->setPrintFooter(true);
    //$pdf->setBarcode("123456");
    // set default monospaced font

    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
    //set margins
    $pdf->SetMargins(5,30,5);
    //set auto page breaks
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $pdf->SetAutoPageBreak(TRUE, 15);
    //set image scale factor
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    // set font
    $pdf->SetFont('dejavusans', '', 8);
   // $pdf->SetFont('freeserif', '', 8);
    // add a page
    $pdf->AddPage($Land,$Page);
    //$str = preg_replace("/[\r\n]/", "<br>", $Html);
    $str = iconv("windows-1254","UTF-8", $Html);
    $pdf->writeHTML($str, true, true, false, false, '');
    $pdf->lastPage();
    $pdf->Output($FileName, 'F');
    $pdf->Close();    
}

    $db = new OracleDB();
    //VAR_DUMP($_REQUEST);
    $DATE1='';
    $DATE2='';
   // VAR_DUMP($_SESSION);
         $DATE1=$_SESSION["DATE1"];
         $DATE2=$_SESSION["DATE2"];
         $sat=1;
         $records;


                 $sql= "SELECT NAME
                 FROM TSM T BETWEEN :DATE1 AND :DATE2";
                 $par = array(":DATE1"=>$DATE1,
                              ":DATE2"=>$DATE2);
                 $q=$db->QueryLimit($sql,$par);



                while($r=$db->Fetch($q)) 
                {
                   $records[]= array( "NAME" => $r["NAME"]
                                      ); 
                        }
                    if(empty($records))
                     {
                         echo("<table align='center'>");
                         echo("<td>");
                         echo("<font color='#CC0000'><b>No record</b></font>");
                         echo("</td>");
                         echo("</table>");
                     }

                     else{
                    $tpl=new Smarty();   
                    $tpl->assign("record",$records);
                    $tpl->assign("t1",$DATE1);
                    $tpl->assign("t2",$DATE2);
                    $rapor_html=$tpl->fetch("../tpl/reports/report1.tpl.html",null,null,null,false);
                    $rapor_filename = Rapor_File_Name();
                    $rapor_baslik = "Report";
                    $rapor_page = "A4";
                    $rapor_land = "P";

                    ?>
4

1 回答 1

0

由于您将表单发布到“report_index.php”,因此您应该将实际保存日期的代码块移动到$_SESSION那里。即移动那部分:

<?php
    $db=new OracleDB();

    session_start();

    if (isset($_POST["REPORT1"]) || isset($_POST["REPORT2"])) {
        $_SESSION["DATE1"] = $_POST["DATE1"];
        $_SESSION["DATE2"] = $_POST["DATE2"];
    }
?>

从“index.php”到“report_index.php”

您的新“report_index.php”可能如下所示:

<?php
    session_start();
    $ret=false;  

    if (isset($_POST["REPORT1"]) || isset($_POST["REPORT2"])) {
        $_SESSION["DATE1"] = $_POST["DATE1"];
        $_SESSION["DATE2"] = $_POST["DATE2"];
    }

    include("../lib/config.php");
    include("../lib/oracle.php");
    include("../lib/smarty/Smarty.class.php");
    include("../lib/tcpdf/tcpdf.php");

    function Rapor_View($Title,$FileName) { ... }
    function Rapor_Pdf($Baslik,$FileName,$Html,$Page="A4",$Land="P") { ... }

    $db = new OracleDB();
    $DATE1 = $_SESSION["DATE1"];
    $DATE2 = $_SESSION["DATE2"];
    ...
于 2013-06-05T08:11:27.400 回答