PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
Bonjour, J' ai une table avec des dates les dates sont de type datetime. J'essaye d'executer une requête juste avec l'année j'ai mis les dates une "combobox" je récupère et j’essaie de l'utiliser et on me renvoie cette erreur (je sais pas si je m'exprime bien) : voila le code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Infos Conso - Gestion EPI</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF8" />
<style type="text/css">
<!--
body {
background-color: #A9EAFE;
}
-->
</style></head>
<body>
<center>
<h3>CONSOMATION ANNUELLE</h3>
<br><br><br><br>
<?php
// set up DB
try {
$strConnection = 'mysql:host=localhost;dbname=epi';
$arrExtraParam= array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8");
$pdo = new PDO($strConnection, 'root', '', $arrExtraParam);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
$msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage();
die($msg);
}
$an=$_GET['an'];
$query = 'SELECT Nom_EPI,SUM(Quantite) FROM `dotation` WHERE YEAR(date ) = YEAR(:date) GROUP BY Nom_EPI';
$mes = $pdo->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$mes->execute(array("YEAR(:date)" => $an));
$nbligne = $mes->rowCount();//nombre lignes
$nbcolonne = $mes->columnCount();//nombre colonnes
if($nbligne>0){
//recuperation nom des colonnes
$colums = $mes->fetch(PDO::FETCH_ASSOC);
$x=1;
foreach($colums as $field_name=>$value) {
$col[$x] = $field_name;
$x++;
}
//tableau
echo '<table cellpadding="2" cellspacing="2" border="5" class="display" id="lignecommande">
<thead>
<tr>';
//titre du tableau
for($i=1;$i<$x;$i++)
echo '<th>'.strtoupper($col[$i]).'</th>';
echo '<th>CHOIX</th>';
echo'
</tr>
</thead>
<tbody>';
//valeur des lignes
$alternate=0;
$mes->execute();
$y=0;
foreach($mes->fetchall() as $t){
$y=$y+1;
if($alternate%2==0){
echo '
<tr id="'.$y.'" class="gradeB">';
for($i=1;$i<$x;$i++){
echo '<td class="center">'.$t[$col[$i]].'</td>';
}
echo '<td class="center"><input type="checkbox" name="check'.$y.'" value="'.$t[$col[1]].'"></td>';
echo'
</tr>';
}
else{
echo '
<tr id="'.$y.'" class="gradeD">';
for($i=1;$i<$x;$i++){
echo '<td class="center">'.$t[$col[$i]].'</td>';
}
echo '<td class="center"><input type="checkbox" name="check'.$y.'" value="'.$t[$col[1]].'"></td>';
echo'
</tr>';
}
$alternate=$alternate+1;
}
echo '
</tbody>
<tfoot>
<tr>';
/*for($i=1;$i<$x;$i++)
echo '<th>'.strtoupper($col[$i]).'</th>';
echo '<th>CHOIX</th>';*/
echo'
</tr>
</tfoot>
</table>
<input type="hidden" id="taille" value="'.$y.'" />';
$var=1;
}
else $var=0;
?>
</center>
</body>
</html> |
ce quio est important c'est juste la requete
merci d'avance!