I want to select a year and it shows me all the data of the year selected but every time it shows me this error : Call to a member function execute() on boolean
Why it appears please?
This is my query :
$sql = (" SELECT code,supplier,date FROM suppliers WHERE
YEAR(date) = $date ");
This is My code :
<?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>
Thanks