Bonsoir tout le monde,
j ai refais un exemple sur internet , problème comme suite:
pour la modification des informations d'un produit un message d'erreur est apparu quand je clique sur le lien modifier et un message d'erreur a l intérieur de mon input
"<br /><b>Warning</b>: Trying to access array offset on value of type bool in <b>C:\xampp\htdocs\projects\php5\modifier.php</b> on line <b>11</b><br />

voici les capture d'ecran

Nom : 1.png
Affichages : 115
Taille : 101,3 Ko
puis
Nom : 2.png
Affichages : 93
Taille : 122,8 Ko
puis
Nom : 3.png
Affichages : 93
Taille : 110,0 Ko
puis
Nom : 4.png
Affichages : 97
Taille : 132,7 Ko
pour le code

index.php
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
46
47
48
 
 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>php5</title>
 
    <style>
        input{
            margin-bottom: 15px;
        }
    </style>
</head>
<body>
    <!-- créer formulaire -->
 
    <form action="" method="post">
        <label for="">Nom de produit</label><input type="text" name="nom" autocomplete="off"><br>
        <label for="">Prix</label><input type="text" name="prix" autocomplete="off"><br>
        <label for="">Quantité</label><input type="number" name="quantite" min="1" autocomplete="off"><br>
        <button type="submit" name="enregistrer">Enregistrer</button>
 
    </form>
</body>
</html>
 <!-- créer connexion pour transmettre les information au BD -->
 
 <?php
 require_once("connect.php");
 if(isset($_POST['enregistrer']))
 {
    $nom=$_POST['nom'];
    $prix=$_POST['prix'];
    $quantite=$_POST['quantite'];
if(!empty($nom) AND !empty($prix) AND !empty($quantite)){
if(strlen($nom)<5){
    echo "cinque caracteres minimum";
} else {
    $req=$con->prepare("INSERT INTO produit(nomproduit, prix, quantite) VALUES (?,?,?)");
    $req->execute(array($nom, $prix, $quantite));
  if($req){   header("location: afficher.php");
  }
}
}else {echo "rempli tt champs";}
 }
 ?>
et

connect.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
<?php
 
try{
$con=new PDO("mysql:localhost=localhost; dbname=php5", "root","");
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e){
    echo "défaut de connexion".$e->getMessage();
}
//pour tester la connexion ecrir la ligne suivante;
// if($con){ echo "connecxion réussite" ;}
 
?>
afficher.php
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
46
47
48
49
50
 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>afficher</title>
    <h4>afficher nos produits</h4>
</head>
<style>
table{
    border: 2px solid blue;
}
td, th{ border: 1px solid red;
    border-collapse: collapse;
 
}
 
</style>
<body>
 
    <table>
 
    <th>ID</th>
    <th>nom produit</th>
    <th>prix</th>
    <th>Quantite</th>
    <th>action</th>
 
 
    <?php
require_once("connect.php");
$req=$con->query("SELECT * FROM produit");
while($aff=$req->fetch()){?>
 
<tr>
<td><?php echo $aff['id'];?></td>
<td><?php echo $aff['nomproduit'];?></td>
<td><?php echo $aff['prix'];?></td>
<td><?php echo $aff['quantite'];?></td>
    <td>
        <a href="modifier.php?id=<?php echo $aff['id']?>">Modifier</a>
        <a href="supprimer.php?id=<?php echo $aff['id']?>">supprimer</a>
    </td>
</tr>
 
<?php }?>
    </table>
</body>
</html>
supprimer.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
<?php
require_once("connect.php");
if(isset($_GET["id"])){
    $id=$_GET["id"];
    $req=$con->prepare("DELETE FROM produit where id= ?");
    $req->execute(array($id));
    if($req){
      header("location: afficher.php");
    }
}
 
 
?>
modifier.php
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
 
<?php
require_once("connect.php");
if(isset($_GET['id'])){
    $id=$_GET['id'];
    $req=$con->prepare("SELECT * FROM produit where id= $id");
    $mod=$req->fetch();
}?>
   <h2>modification produit</h2>
 
<form action="" method="post">
<label for="">Nom de produit</label><input value="<?php echo $mod['nomproduit'];?>" type="text" name="nom" autocomplete="off"><br>
        <label for="">Prix</label><input value="<?php echo $mod['prix'];?>" type="text" name="prix" autocomplete="off"><br>
        <label for="">Quantité</label><input value="<?php echo $mod['quantite'];?>" type="number" name="quantite" min="1" autocomplete="off"><br>
        <button type="submit" name="modifier">Enregistrer Modification</button>
 
    </form>
 
 
    <?php 
if(isset($_POST['modifier']))
{
    $nom=$_POST['nom'];
    $prix=$_POST['prix'];
    $quantite=$_POST['quantite'];
    $req=$con->prepare("UPDATE produit SET nomproduit=?, prix=?, quantite=? where id=$id");
    $req->execute(array($nom, $prix, $quantite));
    if($req){
        header("location:afficher.php");
    }
 
}
    ?>
le souci est dans modifier.php
non seulement quand je clique sur "modifier" DANS le tableau d'affichage globale , le formulaire de modification ne recupere pas les valeurs du produit souhaité modifier plus le message affiche a l'interieur de mon input !!!!!!!!!!!
peut etre probleme id ????
dans l'attente de vos orientation, merci d'avance et agreable soirée