2015-04-03 90 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