Cher (Chère) lecteur(trice) bonjour/bonsoir.
Actuellement étudiant en informatique, je fait une petite application en php pour une gestion d'entrée et sortie de personnes.
J'ai fais une checkbox, défini mes variables tout fonctionnait bien jusqu’à ce que je lui demande d'importer mes données vers le SQL ou il me dis que ma variable action n'est pas définie![]()
Je suis perdu car j'ai refais tout mon code et rien ne cloche, ou alors j'ai vraiment loupé quelque chose mais je ne vois pas quoi. J'ai tester le code sans les checkbox, tout est fonctionnel.
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 <?php require ('connect.php'); if(!empty($_POST)) { $valid = true; if(empty($_POST['nom'])) { $valid=false; $erreurnom ='Indiquez votre Nom'; } if (empty($_POST['prenom'])) { $valid = false; $erreurprenom = 'Indiquez votre prénom'; } if (empty($_POST['identifiant'])) { $valid = false; $erreurident = 'Indiquez votre identifiant personnel <u>/!\</u>'; } if (empty ($_POST['action'])) { $valid = false; $erreuraction = 'Indiquez une entrée ou une sortie'; } if($valid) { $nom = strip_tags($_POST['nom']); // sécurisation des champs contre les injections SQL $prenom = strip_tags($_POST['prenom']); $identifiant = strip_tags($_POST['identifiant']); $action = strip_tags($_POST['action']); $req = $bdd->prepare('INSERT INTO personne(Nom, Prenom, Identifiant, Action) VALUES (:nom, :prenom, :identifiant,:action)'); $req->execute (array(':nom'=>$nom, ':prenom'=>$prenom, ':identifiant'=>$identifiant, ':action'=>$Action)); $req->closecursor(); } } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link href="style.css" rel="stylesheet" /> </head> <title> Enregistrement</title> <body> <div id="content"> <h2> Enregistrez-vous</h2> <form action="index.php" method="post"> <label for="nom" > Entrez votre nom : </label> <input type="text" name="nom" size="50" value="<?php if (isset($_POST['nom'])) echo $_POST['nom']?>" /> <span class="erreur"> <?php if (isset($erreurnom)) echo $erreurnom; ?> </span><br /> <br /> <!-- si la variable erreurnom est existe (si il y a une erreur)alors on l'affiche.--> <label for="prenom"> Entrez votre prénom: </label> <input type="text" name="prenom" size="50" value="<?php if (isset($_POST['prenom'])) echo $_POST['prenom']?>" /> <span class="erreur"> <?php if (isset($erreurprenom)) echo $erreurprenom; ?> </span> <br /> <br /> <label for="identifiant" > Entrez votre identifiant : </label> <input type="text" name="identifiant" size="50" value="<?php if (isset($_POST['identifiant'])) echo $_POST['identifiant']?>" /> <span class="erreur"> <?php if (isset($erreurident)) echo $erreurident; ?> </span> <br /><br /> <p> <label for="action"> Action : </label> <input type="checkbox" name="action" value="Entree" /> Entrée <br /> <input type="checkbox" name="action" value="Sortie" /> Sortie <br /> <span class="erreur"> <?php if (isset($erreuraction)) echo $erreuraction; ?> </span> <br /><br /> </p> <input type="submit" value="Enregistrer" /> </form> </div> </body> </html>
Merci d'avance pour vos réponses !![]()
Partager