2016-04-28 62 views
0

我想选择一年并显示所选年份的所有数据,但每次显示此错误时:调用成员函数execute()on boolean调用成员函数布尔型的execute()

为什么看起来好吗?

这是我的查询:

$sql = (" SELECT code,supplier,date FROM suppliers WHERE 
    YEAR(date) = $date "); 

这是我的代码:

<?php 
if(isset($_POST['submit'])) 
{ 

$date = $_POST['date']; 
$sql = (" SELECT code,supplier,date FROM suppliers WHERE YEAR(date) = $date 

    "); 

$connexion->exec ("set names utf8"); 
$reqd = $connexion->prepare($sql); 
$reqd->execute(); 
$query = $reqd -> fetchAll(PDO::FETCH_ASSOC); 

} 

?> 

<form method="POST" action=""> 
    <select class="form-control select2" style="width: 100%;"> 
     <option selected="selected">2016</option> 
     <option>2015</option> 
     <option>2014</option> 
    </select> 
    <button type="submit" name="submit" class="btn btn-primary"> 
     <span class="glyphicon glyphicon-ok"></span> Submit 
    </button> 

    </form> 

    <table id="example1" class="table table-bordered table-striped"> 
    <thead> 
     <tr> 
    <? if(isset($_POST['date'])) { ?> 
     <th style="text-align:center">code</th> 
     <th style="text-align:center">supplier</th> 
     <th style="text-align:center">date</th> 

    <? } ?>  
       </tr> 
      </thead> 
      <tbody> 
       <?php 

        foreach ($query as $q => $r) : 

        ?> 
       <tr style="text-align: center;"> 
       <td><? echo $r['code']; ?></td> 
       <td><? echo $r['supplier']; ?></td> 
       <td><? echo $r['date']; ?></td> 

       </tr> 

        <?php 
        endforeach; 
        ?> 

      </tbody> 

      </table> 

感谢

+0

$ date = $ _POST ['date'];在使用前检查$ _POST ['date'] isset –

+0

谢谢你的回答。 – user5198335

+0

欢迎您:) –

回答

0

认沽name属性中选择没有名字日期不post

<select name="date" class="form-control select2" style="width: 100%;"> 
设置
+0

谢谢你的回答。它帮助我,但我仍然有相同的概率 – user5198335