Bonjour,
J'essaie de faire un formulaire pour mettre à jour ma base de donnée, cela fonctionne relativement bien, sauf que lorsque certains champs sont vide il refuse d'enregistrer, et également si je supprime les donnes d'un champs.

Voici les deux formulaires :

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
// On inclut la connexion à la base
include('include/db_inc_pdo.php');
 
// On écrit notre requête
$sql = 'SELECT * FROM `testdate` INNER JOIN test on testdate.id = test.id';
 
// On prépare la requête
$query = $pdo->prepare($sql);
 
// On exécute la requête
$query->execute();
 
// On stocke le résultat dans un tableau associatif
$result = $query->fetchAll(PDO::FETCH_ASSOC);
include("menu.php");
?>
 
<link rel="stylesheet" href="menu/dropdown_three.css" type="text/css">
<link rel="stylesheet" href="style.css" type="text/css">
 
 
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Liste</title>
</head>
<body>
 
    <h1>Liste</h1>
    <table>
        <thead>
            <th>ID</th>
            <th>Prenom</th>
            <th>Nom</th>
			<th>Date arrive</th>
            <th>Date depart</th>
            <th>Note</th>
 
        </thead>
        <tbody>
        <?php
            foreach($result as $produit){
        ?>
                <tr>
                    <td><?= $produit['iddate'] ?></td>
                    <td><?= $produit['prenom'] ?></td>
                    <td><?= $produit['nom'] ?></td>					
                    <td><?= $produit['datea'] ?></td>
                    <td><?= $produit['dateb'] ?></td>
                    <td><?= $produit['note'] ?></td>
 
                    <td><a href="essai_details.php?iddate=<?= $produit['iddate'] ?>">Voir</a>  <a href="essai_edit.php?iddate=<?= $produit['iddate'] ?>">Modifier</a>  <a href="essai_delete.php?iddate=<?= $produit['iddate'] ?>">Supprimer</a></td>
                </tr>
        <?php
            }
        ?>
        </tbody>
    </table>
   <h2> <a href="essai_add.php">Ajouter</a></h2>
</body>
</html>
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
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
<?php
require_once('include/db_inc_pdo.php');
var_dump ($_POST);
if(isset($_POST)){
    if(isset($_POST['iddate']) && !empty($_POST['iddate'])
		&& isset($_POST['nom']) && !empty($_POST['nom'])
		&& isset($_POST['prenom']) && !empty($_POST['prenom'])
        && isset($_POST['datea']) && !empty($_POST['datea'])
        && isset($_POST['dateb']) && !empty($_POST['dateb'])
        && isset($_POST['note']) && !empty($_POST['note'])
 
		){
        $iddate = strip_tags($_GET['iddate']);
		$nom = strip_tags($_POST['nom']);
		$prenom = strip_tags($_POST['prenom']);
        $datea = strip_tags($_POST['datea']);
        $dateb = strip_tags($_POST['dateb']);
        $note = strip_tags($_POST['note']);
 
        $sql = "UPDATE `testdate` SET `datea`=:datea, `dateb`=:dateb, `note`=:note, `nom`=:nom, `prenom`=:prenom WHERE `iddate`=:iddate;";
 
        $query = $pdo->prepare($sql);
		$query->bindValue(':nom', $nom, PDO::PARAM_STR);
		$query->bindValue(':prenom', $prenom, PDO::PARAM_STR);
        $query->bindValue(':datea', $datea, PDO::PARAM_STR);
        $query->bindValue(':dateb', $dateb, PDO::PARAM_STR);
        $query->bindValue(':note', $note, PDO::PARAM_STR);
 
        $query->bindValue(':iddate', $iddate, PDO::PARAM_INT);
 
        $query->execute();
 
        header('Location: essai_index.php');
    }
}
 
if(isset($_GET['iddate']) && !empty($_GET['iddate'])){
    $iddate = strip_tags($_GET['iddate']);
    $sql = "SELECT * FROM `testdate` INNER JOIN test on testdate.id = test.id WHERE `iddate`=:iddate;";
 
    $query = $pdo->prepare($sql);
 
    $query->bindValue(':iddate', $iddate, PDO::PARAM_INT);
    $query->execute();
 
    $result = $query->fetch();
}
 
require_once('close.php');
?>
 
<!DOCTYPE html>
<html lang="fr">
<head>
 
    <title>Liste</title>
 
   <link rel="stylesheet" href="menu/dropdown_three.css" type="text/css">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
    <h1>Modifier</h1>
    <form method="post">
        <p>
            <label for="produit">Nom</label>
            <input type="text" name="nom" iddate="nom" value="<?= $result['nom'] ?>">
        </p>
        <p>
            <label for="produit">Prenom</label>
            <input type="text" name="prenom" iddate="prenom" value="<?= $result['prenom'] ?>">
        </p>
 
        <p>
            <label for="produit">Date arrive</label>
            <input type="date" name="datea" iddate="datea" value="<?= $result['datea'] ?>">
        </p>
        <p>
            <label for="prix">Date depart</label>
            <input type="date" name="dateb" iddate="dateb" value="<?= $result['dateb'] ?>">
        </p>
        <p>
            <label for="nombre">Note</label>
            <input type="text" name="note" iddate="note" value="<?= $result['note'] ?>">
        </p>
 
        <p>
            <button>Enregistrer</button>
        </p>
        <input type="hidden" name="iddate" value="<?= $result['iddate'] ?>">
    </form>
</body>
</html>
Ce sont des essais sur une base de test pour ne pas créer de problème sur ma "vraie" base laquelle comporte beaucoup plus de champs, dont certains sont volontairement laissés vides du moins temporairement.

Y a-t-il des erreurs dans mes codes ? ou est-ce que je m'y prends mal ?

D'avance merci pour votre aide