Bonjour,

Je suis débutant en php et j'aimerai créer un bouton supprimer en fin de ligne de tableau pour pouvoir effacer une ligne.

J'ai regardé dans plusieurs sujet et donc trouvé la solution, mais lorsque je lance la suppression ça me renvoie cette erreur : Fatal error: Uncaught Error: Call to a member function exec() on null in /home/vac10260/www/id.php:3 Stack trace: #0 {main} thrown in /home/vac10260/www/id.php on line 3

Voici le code du tableau:

Code : 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
<?php
//connection a la base
    try
    {
        $bdd = new PDO('mysql:host=mysql-vac10260.alwaysdata.net;dbname=********;charset=utf8', 'v****', 'V****!');
    }
    catch (Exception $e)
    {
//en cas d'erreur on affiche un message et on arrete tout
        die('Erreur : ' . $e->getMessage());
    }
    $req = $bdd->query('SELECT *, DATE_FORMAT(date_ins, "%d/%m/%Y") AS date_ins FROM inscription_membre ORDER BY id DESC LIMIT 0, 100');
    ?>
    <h2>Liste d'inscris</h2>
    <table>
        <tr id="entete">
            <th><p>ID</p></th>
            <th><p>Date</p></th>
            <th><p>Course</p></th>
            <th><p>Nom</p></th>
            <th><p>Prenom</p></td>
            <th><p>No licence</p></th>
            <th><p>Distance</p></th>
            <th><p>Email</p></th>
        </tr>
        <?php
 
        while($row = $req->fetch()) 
    {
        ?>
        <tr>
        <td><?php echo $row['id']; ?></td>
        <td><?php echo $row['date_ins']; ?></td>
        <td><?php echo $row['course']; ?></td> 
        <td><?php echo $row['nom']; ?></td>
        <td><?php echo $row['prenom']; ?></td>
        <td><?php echo $row['licence']; ?></td>
        <td><?php echo $row['distance']; ?></td>
        <td><?php echo $row['email']; ?></td>
        <td><a href="id.php?id=<?php echo $row['id'];?>">Supprimer<?php echo $row['id'];?></a></td>
        </tr>
        <?php
    }
        $req->closeCursor();
        ?>
et voici ma page id.php:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
<?php
$id = $row['id'];
$bdd->exec('DELETE FROM inscription_membre WHERE id = $id');
header('Location:liste_inscrit.php');
?>
merci d'avance pour le coup de main