1 pièce(s) jointe(s)
PHP MYSQL Undefined index pourtant tout me semble bon dans la typographie
Bonjour les amis, alors voila, j'ai deux pages, les deux se connectent à MySQL pour afficher des informations.
La première, affiche les utilisateurs de ma bdd "utilisateurs", et me les range sous forme d'input select, chaque value de mon option contient l'ID unique de chaque utilisateur, qui est le même que l'id de l'entrée. Je peux sélectionner un utilisateur dans cette liste et appuyer sur ok.
Cela me renvoie sur la deuxième page, qui se connecte elle aussi à MySQL, en fonction du value de mon option, que j'ai envoyé en POST. Donc, si value = 15 dans la première page, la deuxième me sors les infos de la ligne/utilisateur 15.
Et .. hmmm, c'est la que ça bloque. J'obtiens une erreur, deux enfaite ... :roll:
Voici l'erreur en question !
Pièce jointe 595034
Ce que je ne comprends pas c'est que ligne 8 correspond à ça :
Code:
$IDENTIFIANT = htmlspecialchars($_POST['ID']);
Citation:
Mon post est défini, vu que je l'envoie d'un formulaire qui arrive directement sur la page en question ! :?
Et la ligne 9 correspond elle, à ça :
Code:
$_SESSION['ID'] = htmlspecialchars($_POST['ID']);
Citation:
Même truc, POST est défini grâce au value de mon input select option, et mon formulaire est en method POST ...
Comprends pas :? :?
Si jamais voici mon code, mais j'aimerais comprendre d'où viens le problème
index.php
Code:
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
|
<?php session_start(); ?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Document sans titre</title>
<?php
if (isset($_SESSION['PRENOM'])) // ici mes variables pour savoir quel div a afficher, il y a deux div, choisir un utilisateur ou utilisateur deja choisi
{
$visi_div_choiceuser = "none";
$visi_div_choiceduser = "block";
} else {
$visi_div_choiceuser = "block";
$visi_div_choiceduser = "none";
}
?>
</head>
<body>
<div style="display:<?php echo $visi_div_choiceuser; ?>"> <?php // ici un div si on a choisi aucun utilisateur ?>
<h1>Pour qui lancer une formation ?</h1><br>
<form action="choix_formation.php" method="post">
<select>
<option>Choisir quelqu'un</option>
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=nf', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT ID, NOM FROM utilisateurs'); // On récupère tout le contenu de la table utilisateur
// On affiche chaque entrée une à une
while ($donnees = $reponse->fetch())
{
?>
<option name="ID" value="<?php echo $donnees['ID']; ?>"><?php echo " " . htmlspecialchars($donnees['NOM']); ?></option> <?php // me sort les option de mon select avec tout mes utilisateurs, et en value, son id ?>
<?php
}
$reponse->closeCursor(); // Termine le traitement de la requête
?>
</select>
<input type="submit" value="Démarrer" />
</form>
</div>
<div style="display:<?php echo $visi_div_choiceduser; ?>"> <?php // ici un div si on a deja choisi un utilisateur ?>
<h1>Toujours pour <?php echo $_SESSION['PRENOM']; ?> ?</h1><br>
<input type="submit" value="Oui" id="oui"><input type="submit" value="Non" id="non">
</div>
<script type="text/javascript">
document.getElementById("oui").onclick = function () {
location.href = "choix_formation.php";
};
</script>
<script type="text/javascript">
document.getElementById("non").onclick = function () {
location.href = "destroy_session.php"; <?php // destroy_session est une page qui supprime la session et me renvoie sur cette page, et par conséquent m'affichera l'autre div :p ?>
};
</script>
</body>
</html> |
choix_formation.php
Code:
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
| <?php session_start(); ?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Document sans titre</title>
<?php
$IDENTIFIANT = htmlspecialchars($_POST['ID']);
$_SESSION['ID'] = htmlspecialchars($_POST['ID']);
?>
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=nf', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT * FROM utilisateurs WHERE ID=\'' . $IDENTIFIANT . '\'');
while ($donnees = $reponse->fetch())
{
?>
<?php // ce script permets de changer l'image à côté de chaque bouton, un check si dans la table FORMA_1 = 1, et un cross (une croix) si forma_1 = 0 pareil pour forma2 3 4 5 6 ...
if ($donnees['FORMA_1'] == "1")
{
$FORMA1 = "images/check.png";
} else {
$FORMA1 = "images/cross.png";
}
if ($donnees['FORMA_2'] == "1")
{
$FORMA2 = "images/check.png";
} else {
$FORMA2 = "images/cross.png";
}
if ($donnees['FORMA_3'] == "1")
{
$FORMA3 = "images/check.png";
} else {
$FORMA3 = "images/cross.png";
}
if ($donnees['FORMA_4'] == "1")
{
$FORMA4 = "images/check.png";
} else {
$FORMA4 = "images/cross.png";
}
if ($donnees['FORMA_5'] == "1")
{
$FORMA5 = "images/check.png";
} else {
$FORMA5 = "images/cross.png";
}
if ($donnees['FORMA_6'] == "1")
{
$FORMA6 = "images/check.png";
} else {
$FORMA6 = "images/cross.png";
}
?>
<br>
<?php
$PRENOM = htmlspecialchars($donnees['NOM']); // ici je mets dans une variable le nom, plus pratique hein
?>
</head>
<body>
<form action="formation.php" method="get">
<button type="submit" name="cat" value="1">Démarrer une formation 1 pour <?php echo $PRENOM; ?></button><img style="margin-left:1%;" width="16" height="16" src="<?php echo $FORMA1; ?>"><br>
<button type="submit" name="cat" value="2">Démarrer une formation 2 pour <?php echo $PRENOM; ?></button><img style="margin-left:1%;" width="16" height="16" src="<?php echo $FORMA2; ?>"><br>
<button type="submit" name="cat" value="3">Démarrer une formation 3 pour <?php echo $PRENOM; ?></button><img style="margin-left:1%;" width="16" height="16" src="<?php echo $FORMA3; ?>"><br>
<button type="submit" name="cat" value="4">Démarrer une formation 4 pour <?php echo $PRENOM; ?></button><img style="margin-left:1%;" width="16" height="16" src="<?php echo $FORMA4; ?>"><br>
<button type="submit" name="cat" value="5">Démarrer une formation 5 pour <?php echo $PRENOM; ?></button><img style="margin-left:1%;" width="16" height="16" src="<?php echo $FORMA5; ?>"><br>
<button type="submit" name="cat" value="6">Démarrer une formation 6 pour <?php echo $PRENOM; ?></button><img style="margin-left:1%;" width="16" height="16" src="<?php echo $FORMA6; ?>"><br>
</form>
<?php
}
$reponse->closeCursor(); // Termine le traitement de la requête !!!!!!!!! Mon close cursor est si loin, car sinon mon script cross/check ne fonctionne pas
?><hr>
<?php echo $_SESSION['ID']; ?>
</body>
</html> |
Alors voilà, j'ai regardé la typo dans ma bdd, tout est ok, pas d'espace ni rien en trop, mais cela a l'air de venir du $_POST['ID'] mais je ne comprends pas pourquoi :(
Merci de votre temps en tout cas !