会话变量不返回

时间:2015-02-13 17:34:40

标签: php mysql session

我有这个PHP代码,它使用PHP会话创建的一些变量将一些查询值写入excel电子表格。

<?php
session_start();

error_reporting(0);
require_once("config.php");

require_once('new_stuff/php-excel/Classes/PHPExcel.php');

$link = mysql_connect($dbserver,$dbuser,$dbpass)
    or die('Could not connect: ' . mysql_error());

$sdate = $_SESSION['startdate'];
$edate = $_SESSION['enddate'];

//$sdate = $_POST['startdate'];
list($smonth, $sday, $syear) = split('[/.-]', $sdate);

//$edate = $_POST['enddate'];
list($emonth, $eday, $eyear) = split('[/.-]', $edate);


mysql_select_db($dbname) or die('Could not select database');

// Performing SQL query
$query = 
    'SELECT 
        mantis_category_table.name, 
        mantis_bug_history_table.bug_id, 
        FROM_UNIXTIME(mantis_bug_table.date_submitted, "%m-%d-%Y") AS DATE2, 
        FROM_UNIXTIME(min(mantis_bug_history_table.date_modified), "%m-%d-%Y") AS FirstOfdate_modified,
        ROUND((min(mantis_bug_history_table.date_modified)- mantis_bug_table.date_submitted)/ 86400, 1) as day_difference
    FROM (mantis_bug_table INNER JOIN mantis_bug_history_table 
    ON 
        mantis_bug_table.id = mantis_bug_history_table.bug_id) 
    INNER JOIN 
        mantis_category_table ON mantis_bug_table.category_id = mantis_category_table.id 
    WHERE
        FROM_UNIXTIME(mantis_bug_table.date_submitted, "%Y-%m-%d")
            BETWEEN DATE("'.$syear.'-'.$smonth.'-'.$sday.'") AND DATE("'.$eyear.'-'.$emonth.'-'.$eday.'")
    GROUP BY 
        mantis_category_table.name, mantis_bug_table.category_id, mantis_bug_table.date_submitted, mantis_bug_table.status, mantis_bug_history_table.bug_id, mantis_bug_history_table.field_name, mantis_bug_history_table.new_value 
    HAVING 
        (((mantis_bug_table.status)<>90) AND ((mantis_bug_history_table.field_name)="status") AND ((mantis_bug_history_table.new_value)="50")) 
    ORDER BY 
        mantis_category_table.name, FROM_UNIXTIME(mantis_bug_table.date_submitted, "%m")';

echo $query;

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);

当我回显查询时,我发现startdate没有传递给页面,即使它写的完全相同就像enddate一样,它正在显示。

有人能指出我的会话变量收集技术中的缺陷吗?

1 个答案:

答案 0 :(得分:0)

session_start();

$_SESSION['startdate'] = date('Y-m-d');

$_SESSION['enddate'] = date('Y-m-d');


$sdate = $_SESSION['startdate'];

$edate = $_SESSION['enddate'];

$sday = date('d', strtotime($sdate));

$smonth = date('m', strtotime($sdate));

$syear = date('Y', strtotime($sdate));



$eday = date('d', strtotime($edate));

$emonth = date('m', strtotime($edate));

$eyear = date('Y', strtotime($edate));



$query = 
    'SELECT 
        mantis_category_table.name, 
        mantis_bug_history_table.bug_id, 
        FROM_UNIXTIME(mantis_bug_table.date_submitted, "%m-%d-%Y") AS DATE2, 
        FROM_UNIXTIME(min(mantis_bug_history_table.date_modified), "%m-%d-%Y") AS FirstOfdate_modified,
        ROUND((min(mantis_bug_history_table.date_modified)- mantis_bug_table.date_submitted)/ 86400, 1) as day_difference
    FROM (mantis_bug_table INNER JOIN mantis_bug_history_table 
    ON 
        mantis_bug_table.id = mantis_bug_history_table.bug_id) 
    INNER JOIN 
        mantis_category_table ON mantis_bug_table.category_id = mantis_category_table.id 
    WHERE
        FROM_UNIXTIME(mantis_bug_table.date_submitted, "%Y-%m-%d")
            BETWEEN DATE("'.$syear.'-'.$smonth.'-'.$sday.'") AND DATE("'.$eyear.'-'.$emonth.'-'.$eday.'")
    GROUP BY 
        mantis_category_table.name, mantis_bug_table.category_id, mantis_bug_table.date_submitted, mantis_bug_table.status, mantis_bug_history_table.bug_id, mantis_bug_history_table.field_name, mantis_bug_history_table.new_value 
    HAVING 
        (((mantis_bug_table.status)<>90) AND ((mantis_bug_history_table.field_name)="status") AND ((mantis_bug_history_table.new_value)="50")) 
    ORDER BY 
        mantis_category_table.name, FROM_UNIXTIME(mantis_bug_table.date_submitted, "%m")';

echo $query;