Bonjour,
Voila je rencontre un petit problème avec mon code.
Décrivez ici votre code ou ce que vous cherchez à faire
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<h1> Reservation garderie </h1>
</head>
<body>
<table>
<tr>
<th> </th>
<th> Lundi </th>
<th> Mardi </th>
<th> Mercredi </th>
<th> Jeudi </th>
<th> Vendredi </th>
</tr>
<tr>
<th> Matin </th>
<th> <INPUT type="checkbox" name="lundi_matin" value="1"> </th>
<th> <INPUT type="checkbox" name="mardi_soir" value="1"> </th>
<th> <INPUT type="checkbox" name="mercredi_matin" value="1"> </th>
<th> <INPUT type="checkbox" name="jeudi_matin" value="1"> </th>
<th> <INPUT type="checkbox" name="vendredi_matin" value="1"> </th>
</tr>
<tr>
<th> Soir </th>
<th> <INPUT type="checkbox" name="lundi_soir" value="2"> </th>
<th> <INPUT type="checkbox" name="mardi_soir" value="2"> </th>
<th> <INPUT type="checkbox" name="mercredi_soir" value="2"> </th>
<th> <INPUT type="checkbox" name="jeudi_soir" value="2"> </th>
<th> <INPUT type="checkbox" name="vendredi_soir" value="2"> </th>
</tr>
</table>
</body>
<br></br>
<INPUT TYPE="submit" NAME="submit" VALUE=" Envoyer ">
<form action="traitementgarderie.php" method="post">
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<?php
$lundi_matin = true;
$mardi_matin = true;
$mercredi_matin = true;
$jeudi_matin = true;
$vendredi_matin = true;
$lundi_matin = false;
$mardi_matin = false;
$mercredi_matin = false;
$jeudi_matin = false;
$vendredi_matin = false;
error_reporting(E_ALL);
if(isset($_POST['submit']))
{
$bdd = new PDO('mysql:host=localhost;dbname=phplogin;charset=utf8', 'root', '');
try
{
$bdd = new PDO('mysql:host=localhost;dbname=phplogin;charset=utf8', 'root', '');
$req = "INSERT INTO garderie(lundi_matin) VALUES ('', :checkbox);");
$req .= "(lundi_matin, lundi_soir, mardi_matin, mardi_soir, mercredi_matin, mercredi_soir, jeudi_matin, jeudi_soir, vendredi_matin, vendredi_soir)";
$stmt = $bdd->prepare($req);
$stmt->bindValue('lundi_matin',htmlentities(trim($_POST['lundi_matin'])),PDO::PARAM_STR);
$stmt->bindValue('lundi_soir',htmlentities(trim($_POST['lundi_soir'])),PDO::PARAM_STR);
$stmt->bindValue('mardi_matin',htmlentities(trim($_POST['mardi_matin'])),PDO::PARAM_STR);
$stmt->bindValue('mardi_soir',htmlentities(trim($_POST['mardi_soir'])),PDO::PARAM_STR);
$stmt->bindValue('mercredi_matin',htmlentities(trim($_POST['mercredi_matin'])),PDO::PARAM_STR);
$stmt->bindValue('mercredi_soir',htmlentities(trim($_POST['mercredi_soir'])),PDO::PARAM_STR);
$stmt->bindValue('jeudi_matin',htmlentities(trim($_POST['jeudi_matin'])),PDO::PARAM_STR);
$stmt->bindValue('jeudi_soir',htmlentities(trim($_POST['jeudi_soir'])),PDO::PARAM_STR);
$stmt->bindValue('vendredi_matin',htmlentities(trim($_POST['vendredi_matin'])),PDO::PARAM_STR);
$stmt->bindValue('vendredi_soir',htmlentities(trim($_POST['vendredi_soir'])),PDO::PARAM_STR);
}
if(isset($_POST["lundi_matin"])
{
$lundi_matin = $_POST['lundi_matin'];
}else{
echo faux
};
};
?>
Enregistrer les boutons radios cochés dans la BDD
Rien
salut lecjoh,
si tu pourrais nous indique le checkbox qui cause problème ou si tu peux nous indique l'erreur qui survient lorsque tu cliques sur le bouton d soumission
Salut, bah tout d'abord j'aimerais que les cases cochées s'enregistrent dans la BDD. En cliquant sur le bouton de soumission, rien ne se passe.
Ce que tu devrais faire normalement comme ceci (partie formulaire) est d'entourer tout ceci avec la balise <form>
<!-- à entourer avec la balise <form>-->
<form>
<table>
<tr>
<th> </th>
<th> Lundi </th>
<th> Mardi </th>
<th> Mercredi </th>
<th> Jeudi </th>
<th> Vendredi </th>
</tr>
<tr>
<th> Matin </th>
<th> <INPUT type="checkbox" name="lundi_matin" value="1"> </th>
<th> <INPUT type="checkbox" name="mardi_soir" value="1"> </th>
<th> <INPUT type="checkbox" name="mercredi_matin" value="1"> </th>
<th> <INPUT type="checkbox" name="jeudi_matin" value="1"> </th>
<th> <INPUT type="checkbox" name="vendredi_matin" value="1"> </th>
</tr>
<tr>
<th> Soir </th>
<th> <INPUT type="checkbox" name="lundi_soir" value="2"> </th>
<th> <INPUT type="checkbox" name="mardi_soir" value="2"> </th>
<th> <INPUT type="checkbox" name="mercredi_soir" value="2"> </th>
<th> <INPUT type="checkbox" name="jeudi_soir" value="2"> </th>
<th> <INPUT type="checkbox" name="vendredi_soir" value="2"> </th>
</tr>
</table>
</form>
As-tu préciser les options suplementaires à la balise <form> comme ceci
<form action="page_traitement.php" method="post">
</form>
Salut
Je tiens a signaler qu'il est possible que je dise des conneries, je débute dans le php mysql :
j'ai remarquais plusieurs erreurs dans ton traitement :
Pour le try catch un truc dans le genre :
// Connexion à la base de donnée
try {
$bdd = new PDO('mysql:host=localhost;dbname=phplogin;', 'root', '');
} catch(PDOException $e) {
exit($e->getMessage());
}
Pour les requetes un truc dans le genres :
$req = $bdd->prepare('INSERT INTO garderie (ta_table) VALUES(:param1, :param2)');
$req->execute(array(':param1' => $params1, ':param2' => $param2));
ou bien :
$req = $bdd->prepare('INSERT INTO garderie (ta_table) VALUES (:param1, :param2)');
$req->bindValue(':param1', $param1);
$req->bindValue(':param2', $param2);
$req->execute();
Il y a sans doute des erreurs je suis sur mon téléphone désolé
Tu dois d'abord regarder si le bouton radio est coché puis ensuite envoyé le résultat dans ta base de donné via une requête et non envoyé la requête sans tester la radio.