我想选择一年,它会显示所选年份的所有数据,但每次显示此错误时:在布尔值上调用成员函数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 :(得分:0)
在name
post
属性而没有名称日期
<select name="date" class="form-control select2" style="width: 100%;">