2013-05-07 114 views
0

我無法讀取帖子值「To」和「From」在php頁面上設置的日期。 任何幫助,將不勝感激。這裏是代碼: -PHP無法讀取帖子值

在代碼中你可以找到三個代碼片段,我試過了,但都沒有工作。不確定需要修復。

<? 
include("adminlogin.php"); 

include("classes/tc_calendar.php"); 

$myCalendar = new tc_calendar("stdt", true, false); 
$myCalendar->setIcon("images/iconCalendar.gif"); 
$myCalendar->setPath("./"); 
$myCalendar->setYearInterval(2000, 2015); 
$myCalendar->dateAllow('2000-01-01', '2015-12-31'); 
$myCalendar->setDateFormat('j F Y'); 
//$myCalendar->setHeight(350);  
//$myCalendar->autoSubmit(true, "form1"); 

$myCalendar2 = new tc_calendar("enddt", true, false); 
$myCalendar2->setIcon("images/iconCalendar.gif"); 
$myCalendar2->setPath("./"); 
$myCalendar2->setYearInterval(2000, 2015); 
$myCalendar2->dateAllow('2000-01-01', '2015-12-31'); 
$myCalendar2->setDateFormat('j F Y'); 
//$myCalendar2->setHeight(350); 
//$myCalendar2->autoSubmit(true, "form1"); 

$stdt1=$_POST['stdt']; 
$enddt1=$_POST['enddt']; 
echo "dates are"; 
echo $stdt1; 
echo $enddt1; 

// function to download report 
function export_excel_csv() 
{ 
    $init_sql = "select distinct(proj_id) from timeshiftentry_master where dt>='$stdt1' and dt<='$enddt1'"; 
    $init_res=mysql_query($init_sql); 

    //header info for browser 
    $filename = "WP_List_" . date('Ymd') . ".xls"; 
    header("Content-Type: application/vnd.ms-excel; name='excel'"); 
    header("Content-Disposition: attachment; filename=\"$filename\""); 
    header("Pragma: no-cache"); 
    header("Expires: 0"); 

    /*******Start of Formatting for Excel*******/ 
    //define separator (defines columns in excel & tabs in word)  
    $sep = "\t"; //tabbed character 
    ob_end_clean(); 

    //start of printing column names as names of MySQL fields 
    /*for ($i = 0; $i < mysql_num_fields($result); $i++) 
    { 
     if($i == 0) 
     { 
      echo "S. No." . "\t"; 
     } 
     echo mysql_field_name($result,$i) . "\t"; 
    } 
    echo "Employee Name" . "\t"; 
    echo "Hours Booked" . "\t"; 
    print("\n");*/ 

    $SerialNum = 0; 
    while($init_row=mysql_fetch_array($init_res)) 
    { 
     $sql = "SELECT * FROM project_master where proj_id='$init_row[0]'"; 
     //execute query 
     $result = mysql_query($sql) or die (mysql_error()); 
     //end of printing column names 
     //start while loop to get data 
     while($row = mysql_fetch_array($result)) 
     { 
      // get the emplyoee details 
      $projid=$row[0]; 
      $projnm=$row[1]; 
      $sql_emp="Select distinct(emp_no),emp_name from timeshiftentry_master where proj_id='$projnm' and dt>='$stdt1' and dt<='$enddt1'"; 
      $res_emp=mysql_query($sql_emp); 
      while($row_emp=mysql_fetch_array($res_emp)) 
      { 
       $sql_hrs="select sum(wrkhrs) from timeshiftentry_master where proj_name='$projnm' and emp_no='$row_emp[0]' and dt>='$stdt1' and dt<='$enddt1'"; 
       $res_hrs=mysql_query($sql_hrs); 
       $row_hrs=mysql_fetch_array($res_hrs); 
       if($row_hrs[0] >= 0) 
       { 
        $SerialNum++; 
        // insert to excel 
        $schema_insert = ""; 
        for($j=0; $j<mysql_num_fields($result);$j++) 
        { 
         if($j==0) 
         { 
          $schema_insert .= "$SerialNum".$sep; 
         } 
         if(!isset($row[$j])) 
          $schema_insert .= "NULL".$sep; 
         elseif ($row[$j] != "") 
          $schema_insert .= "$row[$j]".$sep; 
         else 
          $schema_insert .= "".$sep; 
        } 
        $schema_insert .= "$row_emp[1]".$sep; 
        $schema_insert .= "$row_hrs[0]".$sep; 
        $schema_insert = str_replace($sep."$", "", $schema_insert); 
        $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); 
        $schema_insert .= "\t"; 

        print(trim($schema_insert)); 
        print "\n"; 
        // inserted one row 
       } 
      } 
     } 
    } 
    exit(); 
} 

/*if(!isset($_POST)) // Code Snippet 1 
{ 
    export_excel_csv(); 
}*/ 

/*if($_SERVER['REQUEST_METHOD']=="POST") // Code Snippet 2 
{ 
    $chk1= $_POST['download']; 

    if($chk1=='Download') 
    { 
     export_excel_csv(); 
    } 
} 
else 
{ 

}*/ 

if($_SERVER['REQUEST_METHOD']=="POST") // Code Snippet 3 
{ 
    if(isset($_POST['download'])) 
    { 
     $stdt1=$_POST['stdt']; 
     $enddt1=$_POST['enddt']; 
     export_excel_csv(); 
    } 
} 
else 
{ 
} 

?> 

<script language="javascript"> 
function check() 
{ 
    if(download) 
    { 
     if(document.f1.stdt.value=="0000-00-00") 
     { 
      alert("Please Enter Start Date") 
      show=false; 
      return false; 
     } 
     if(document.f1.enddt.value=="0000-00-00") 
     { 
      alert("Please Enter the End Date") 
      show=false; 
      return false; 
     } 
     if(document.f1.stdt.value>document.f3.enddt.value) 
     { 
      alert("Dates not allowed.") 
      show=false; 
      return false; 
     } 
    } 
    return true; 
} 
</script> 

<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 

<title>Bombardier TSM System</title> 

<style type="text/css"> 
<!-- 
.style1 {font-size: small} 
.style2 {color: #FFFFFF} 
.style3 {font-size: x-small} 
--> 
</style> 

</head> 

<body> 

<form name="f1" method="POST" action="" onSubmit="return check()"> 

<script language="javascript" src="calendar.js"></script> 

<br> 

<table align="center" cellspacing="5"> 

<tr> 
<th colspan="2"><font color="#993300" size="4">Download Hours Booking Report</font></th> 
</tr> 

<tr> 
<td>&nbsp;</td> 
</tr> 

<tr> 
<td align="right"><font color="#993300">From : </font></td> 
<td><?$myCalendar->writeScript();?></td> 
</tr> 

<tr> 
<td align="right"><font color="#993300">To : </font></td> 
<td><?$myCalendar2->writeScript();?></td> 
</tr> 

<tr> 
<td>&nbsp;</td> 
</tr> 

<tr> 
<td colspan="2" align="center"><input type="submit" name="download" value="Download" id="download" onSubmit="download=true"/></td 
</tr> 

</table> 

<p>&nbsp;</p> 
<p>&nbsp;</p> 
<p>&nbsp;</p> 

<?include("footer.php");?> 

</form> 
</body> 
</html> 
+0

$ myCalendar-> writeScript() - 這裏產生什麼樣的HTML代碼? 它必須包含帶名稱的輸入標籤。 – Svetoslav 2013-05-07 04:45:02

+0

輸入標籤的類型??你能給我確切的代碼嗎? – 2013-05-07 04:50:15

+0

$ myCalendar-> writeScript()將提供一個日曆符號,點擊它將允許用戶選擇日期,月份,年份。 – 2013-05-07 04:52:47

回答

0

你必須在函數傳遞參數使用這個值,這樣

function export_excel_csv($stdt1, $enddt1) { // create function with parameter here 

} 

,並同時呼籲必須通過相關參數

if($_SERVER['REQUEST_METHOD']=="POST") // Code Snippet 3 
{ 
    if(isset($_POST['download'])) 
    { 
     $stdt1=$_POST['stdt']; 
     $enddt1=$_POST['enddt']; 
     export_excel_csv($stdt1, $enddt1); // pass parameter here 
    } 
} 
0

其實我不知道這個日曆類和功能,但我認爲你可以做一件事來解決你的問題,如下所示,

首先,你可以使用JavaScript通過document.f1.stdt.value得到這個值 & document.f1.enddt.value

對於PHP,你可以使用:$_REQUEST["stdt"];

還你可以指任何幫助這個鏈接有關tc_calendar

http://www.triconsole.com/php/calendar_datepicker.php

讓我知道,如果有更多需要幫助。

謝謝

0

您已經定義了函數範圍之外的變量,您不能訪問它。 See the PHP manual for more details

或者你的問題的解決方案是

function export_excel_csv() 
{ 
    global $stdt1,$enddt1; 
...... 

}