没有获得表格中的选择值

时间:2015-04-03 01:47:17

标签: php

我有一个表格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-01'。为什么呢?

1 个答案:

答案 0 :(得分:0)

您在日期参数中缺少date部分。

试试这个:

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