2015-04-03 35 views
-2

我有一個proplem形式的PHP。當我提交表單時,它沒有獲得選擇選項的值。我嘗試了許多時間和許多方式,但它不起作用。請幫幫我。感謝 代碼:沒有得到價值的選擇在形式

<form method="post" action="" id="form_search" > 
<article class="module width_full"> 
<header><h3>Thống kê CCU</h3></header> 
<div class="module_content"> 
<fieldset> 
<label>Month</label> 
<select name="month"> 
<?php 
$stt=0; 
$query=mysql_query("select DATE_FORMAT(date,'%m') as month from skycity_log.ccu_log GROUP BY month ORDER BY month ASC") or die (mysql_error()); 
while($row = mysql_fetch_array($query)){ 

echo"<option value='$row[month]'>$row[month]</option>";}?> 
</select> 
</fieldset> 
<fieldset> 
<label>Year</label> 
<select name="year"> 
<?php 
$query=mysql_query("select DATE_FORMAT(date,'%Y') as year from skycity_log.ccu_log GROUP BY year ORDER BY year ASC") or die (mysql_error()); 
while($row = mysql_fetch_array($query)){ 
echo"<option value='$row[year]'>$row[year]</option>";} 
?> 
</select> 
</fieldset> 
<div class="clear"></div> 
</div> 
<div class="submit_link"> 
<input type="submit" name="s_t" value="Search" class="alt_btn"> 
</div> 
</article> 
</form> 
<?php 
     if(isset($_POST['s_t'])){ 
      $month=$_POST['month']; 
      $year=$_POST['year']; 
      $date = $month."-".$year; 
      $d=strtotime($date); 
      echo date("Y-m",$d); 
      } 
     ?> 

考試:當我選擇值= 2選擇「月」和值=「2015年」中選擇「年」,並提交表單,然後導致不=「2015-02」這一結果= 「1970年至1901年」。爲什麼?

+0

什麼是年份和月份的$ _POST價值? – dbinns66 2015-04-03 01:51:51

+0

如果你'echo $ date',你會看到什麼? – Barmar 2015-04-03 01:54:03

+0

你是什麼意思?你可以寫更多的細節? – 2015-04-03 01:55:09

回答

0

您在日期參數中缺少date部分。

試試這個:

$month=$_POST['month']; 
    $year=$_POST['year']; 
    $date = "1-" . $month."-".$year; 
    $d=strtotime($date); 
    echo date("Y-m",$d); 
+0

'strtotime'失敗,如果你沒有給出完整格式 – 2015-04-03 02:00:55

+0

是的,謝謝你的幫助。這工作。 :) – 2015-04-03 02:03:17