Bonjour,
lorsque je valide l'adresse de mon code dans l'url du navigateur, j'ai un message d'erreur qui s'affiche comme suit:
LA DATE DE PAIEMENT:
Fatal error: Uncaught Error: Call to a member function fetch() on string in C:\xampp\htdocs\somme_jour.php:49 Stack trace: #0 {main} thrown in C:\xampp\htdocs\somme_jour.php on line 49
NOM ET PRENOMS MONTANT (FCFA) DATE DE PAIEMENT TOTAL =
lorsque j'écris une date dans le formulaire et que je valide le code me renvoie bien les résultats attendus sans le message d'erreur. Je veux donc que le message d'erreur ne s'affiche plus dès que je valide l'adresse de mon code à l'url. J'ai fouillé partout mais je n'y parviens pas. je pense que cette erreur est due à la struture de mon code. J'ai donc un code qui marche mais qui m'affiche ce message : Fatal error: Uncaught Error: Call to a member function fetch() on string in C:\xampp\htdocs\somme_jour.php:49 Stack trace: #0 {main} thrown in C:\xampp\htdocs\somme_jour.php on line 49
Prière de bien vouloir m'aider à sortir de ce pétrin
Merci d'avance.
mon code:
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php $req1 = ""; if (isset($_POST['search']) && !empty ($_POST['search'])) { try { $db = new PDO('mysql:host=localhost;dbname=bdd', 'XX','X', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); } catch (PDOException $e) { die ($e->getMessage()); } $query = $_POST['search']; $req1 = $db->prepare(" SELECT SUM(versement) AS total FROM cinquiemev WHERE date_paiement LIKE ? "); $req2 = $db->prepare(" SELECT noms, versement, date_paiement FROM cinquiemev WHERE date_paiement LIKE ? "); $req1->execute(array('%' . $query . '%')); $req2->execute(array('%' . $query . '%')); } ?> <!DOCTYPE html> <html lang="fr" dir="ltr"> <head> <meta charset="utf-8"> <title>BILAN QUOTIDIENT</title> </head> <body><br> <form method="post"> <label for="search">LA DATE DE PAIEMENT: </label> <input type="search" name="search" value=""> <input type="submit" name="submit" value="valider"> </form></br> <table width="80%" border="1" cellspacing="0" bordercolor="#FFFFFF"> <thead> <tr> <td><B><U>NOM ET PRENOMS</U></B></td> <td><B><U>MONTANT (FCFA)</U></B></td> <td><B><U>DATE DE PAIEMENT</U></B></td> <td><span style="position: absolute; bottom: 300px; left: 1080px; width: 242px; heigth: 70px; color: red;"> TOTAL = </span></td> </tr> </thead> <tbody> <?php while($data = $req1->fetch(PDO::FETCH_ASSOC)):;?> <tr> <td><span style="position: absolute; bottom: 300px; left: 1160px; width: 242px; heigth: 70px;"><?php echo htmlspecialchars($data['total']);?> FCFA</span></td> </tr> <?php endwhile;?> <?php while($data = $req2->fetch(PDO::FETCH_ASSOC)):;?> <tr> <td><?php echo htmlspecialchars($data['noms']);?></td> <td><?php echo htmlspecialchars($data['versement']);?></td> <td><?php echo htmlspecialchars($data['date_paiement']);?></td> </tr> <?php endwhile; ?> </tbody> </table> </body> </html>
Partager