Pb checkbox retour valeur
Résolu
lecjoh59
Messages postés
84
Statut
Membre
-
jordane45 Messages postés 40050 Statut Modérateur -
jordane45 Messages postés 40050 Statut Modérateur -
Bonjour, j'ai une eptite erreur dans mon code que j'arrive pas à déceler :
J'ai ça en erreur : Warning: PDOStatement::execute() expects parameter 1 to be array, string given in C:\Program Files\EasyPHP-DevServer-14.1VC9\data\localweb\projet\reservation_garderie.php on line 95
error_reporting(E_ALL);
require_once "cnxBDD.php";
$lundi_matin = isset($_POST['lundi_matin']);
$mardi_matin = isset($_POST['mardi_matin']);
$mercredi_matin = isset($_POST['mercredi_matin']);
$jeudi_matin = isset($_POST['jeudi_matin']);
$vendredi_matin = isset($_POST['vendredi_matin']);
$lundi_soir = isset($_POST['lundi_soir']);
$mardi_soir = isset($_POST['mardi_soir']);
$mercredi_soir = isset($_POST['mercredi_soir']);
$jeudi_soir = isset($_POST['jeudi_soir']);
$vendredi_soir = isset($_POST['vendredi_soir']);
if (isset($_POST['lundi_matin'])) {
$lundi_matin = 1;
} else {
$lundi_matin = 0;
}
if (isset($_POST['lundi_soir'])) {
$lundi_soir = 1;
} else {
$lundi_soir = 0;
}
if (isset($_POST['mardi_matin'])) {
$mardi_matin = 1;
} else {
$mardi_matin = 0;
}
if (isset($_POST['mardi_soir'])) {
$mardi_soir = 1;
} else {
$mardi_soir = 0;
}
if (isset($_POST['mercredi_matin'])) {
$mercredi_matin = 1;
} else {
$mercredi_matin = 0;
}
if (isset($_POST['mercredi_soir'])) {
$mercredi_soir = 1;
} else {
$mercredi_soir = 0;
}
if (isset($_POST['jeudi_matin'])) {
$jeudi_matin = 1;
} else {
$jeudi_matin = 0;
}
if (isset($_POST['jeudi_soir'])) {
$jeudi_soir = 1;
} else {
$jeudi_soir = 0;
}
if (isset($_POST['vendredi_matin'])) {
$vendredi_matin = 1;
} else {
$vendredi_matin = 0;
}
if (isset($_POST['vendredi_soir'])) {
$vendredi_soir = 1;
} else {
$vendredi_soir = 0;
}
$req = 'INSERT INTO garderie ($lundi_matin, $lundi_soir, $mardi_matin, $mardi_soir, $mercredi_matin, $mercredi_soir, $jeudi_matin, $jeudi_soir, $vendredi_matin, $vendredi_soir)
VALUES = ""';
$stmt = $bdd->prepare($req);
$stmt->bindParam(':lundi_matin',$lundi_matin);
$stmt->bindParam(':lundi_soir',$lundi_soir);
$stmt->bindParam(':mardi_matin',$mardi_matin);
$stmt->bindParam(':mardi_soir',$mardi_soir);
$stmt->bindParam(':mercredi_matin',$mercredi_matin);
$stmt->bindParam(':mercredi_soir',$mercredi_soir);
$stmt->bindParam(':jeudi_matin',$jeudi_matin);
$stmt->bindParam(':jeudi_soir',$jeudi_soir);
$stmt->bindParam(':vendredi_matin',$vendredi_matin);
$stmt->bindParam(':vendredi_soir',$vendredi_soir);
$stmt->execute($req);
J'ai ça en erreur : Warning: PDOStatement::execute() expects parameter 1 to be array, string given in C:\Program Files\EasyPHP-DevServer-14.1VC9\data\localweb\projet\reservation_garderie.php on line 95
A voir également:
- Pb checkbox retour valeur
- Retour à la ligne excel - Guide
- Logiciel gratuit calcul valeur nutritionnelle - Télécharger - Santé & Bien-être
- Formule excel si contient texte alors valeur ✓ - Forum Excel
- Retour à la ligne chatgpt - Forum Réseaux sociaux
- Aller à la ligne lors de la rédaction d'un message ✓ - Forum MacOS
9 réponses
Bonjour,
La récupération des variables ... est à moitié bonne ^^
Tu as bien utilisé un ISSET.... mais il te manque le "reste" du code.
Par exemple :
Ne te retournera que true ou false ... si la variable EXISTE....
Pour récupérer le CONTENU de ta variable il faut écrire :
Je te laisse faire la correction pour toutes tes autres variables.
Ensuite, dans la ligne :
tu ne dois rien mettre entre les parenthèses.....
(sauf si tu utilises un ARRAY de datas...... mais pas les BINDPARAM )
La récupération des variables ... est à moitié bonne ^^
Tu as bien utilisé un ISSET.... mais il te manque le "reste" du code.
Par exemple :
$lundi_matin = isset($_POST['lundi_matin']);
Ne te retournera que true ou false ... si la variable EXISTE....
Pour récupérer le CONTENU de ta variable il faut écrire :
$lundi_matin = isset($_POST['lundi_matin']) ? $_POST['lundi_matin'] : '';
Je te laisse faire la correction pour toutes tes autres variables.
Ensuite, dans la ligne :
$stmt->execute($req);
tu ne dois rien mettre entre les parenthèses.....
(sauf si tu utilises un ARRAY de datas...... mais pas les BINDPARAM )
lecjoh59
Messages postés
84
Statut
Membre
En modifiant les variables, j'ai rien en enregistrement.
jordane45
Messages postés
40050
Statut
Modérateur
4 756
Montre le code corrigé.
error_reporting(E_ALL);
require_once "cnxBDD.php";
$lundi_matin = isset($_POST['lundi_matin']) ? $_POST['lundi_matin'] : '';
$mardi_matin = isset($_POST['mardi_matin']) ? $_POST['mardi_matin'] : '';
$mercredi_matin = isset($_POST['mercredi_matin']) ? $_POST['mercredi_matin'] : '';
$jeudi_matin = isset($_POST['jeudi_matin']) ? $_POST['jeudi_matin'] : '';
$vendredi_matin = isset($_POST['vendredi_matin']) ? $_POST['vendredi_matin'] : '';
$lundi_soir = isset($_POST['lundi_soir']) ? $_POST['lundi_soir'] : '';
$mardi_soir = isset($_POST['mardi_soir']) ? $_POST['mardi_soir'] : '';
$mercredi_soir = isset($_POST['mercredi_soir']) ? $_POST['mercredi_soir'] : '';
$jeudi_soir = isset($_POST['jeudi_soir']) ? $_POST['jeudi_soir'] : '';
$vendredi_soir = isset($_POST['vendredi_soir']) ? $_POST['vendredi_soir'] : '';
if (isset($_POST['lundi_matin'])) {
$lundi_matin = 1;
} else {
$lundi_matin = 0;
}
if (isset($_POST['lundi_soir'])) {
$lundi_soir = 1;
} else {
$lundi_soir = 0;
}
if (isset($_POST['mardi_matin'])) {
$mardi_matin = 1;
} else {
$mardi_matin = 0;
}
if (isset($_POST['mardi_soir'])) {
$mardi_soir = 1;
} else {
$mardi_soir = 0;
}
if (isset($_POST['mercredi_matin'])) {
$mercredi_matin = 1;
} else {
$mercredi_matin = 0;
}
if (isset($_POST['mercredi_soir'])) {
$mercredi_soir = 1;
} else {
$mercredi_soir = 0;
}
if (isset($_POST['jeudi_matin'])) {
$jeudi_matin = 1;
} else {
$jeudi_matin = 0;
}
if (isset($_POST['jeudi_soir'])) {
$jeudi_soir = 1;
} else {
$jeudi_soir = 0;
}
if (isset($_POST['vendredi_matin'])) {
$vendredi_matin = 1;
} else {
$vendredi_matin = 0;
}
if (isset($_POST['vendredi_soir'])) {
$vendredi_soir = 1;
} else {
$vendredi_soir = 0;
}
$req = 'INSERT INTO garderie (lundi_matin, lundi_soir, mardi_matin, mardi_soir, mercredi_matin, mercredi_soir, jeudi_matin, jeudi_soir, vendredi_matin, vendredi_soir)
VALUES = ""';
$stmt = $bdd->prepare($req);
$stmt->bindParam(':lundi_matin',$lundi_matin);
$stmt->bindParam(':lundi_soir',$lundi_soir);
$stmt->bindParam(':mardi_matin',$mardi_matin);
$stmt->bindParam(':mardi_soir',$mardi_soir);
$stmt->bindParam(':mercredi_matin',$mercredi_matin);
$stmt->bindParam(':mercredi_soir',$mercredi_soir);
$stmt->bindParam(':jeudi_matin',$jeudi_matin);
$stmt->bindParam(':jeudi_soir',$jeudi_soir);
$stmt->bindParam(':vendredi_matin',$vendredi_matin);
$stmt->bindParam(':vendredi_soir',$vendredi_soir);
$req = array(":lundi_matin"=> $lundi_matin,":lundi_soir"=> $lundi_soir,":mardi_matin"=> $mardi_matin, ":mardi_soir" => $mardi_soir, ":mercredi_matin" => $mercredi_soir, ":jeudi_matin" => $jeudi_matin, ":jeudi_soir" => $jeudi_soir, ":vendredi_matin" => $vendredi_matin, ":vendredi_soir" => $vendredi_soir);
$stmt->execute();
Pourquoi est-ce que tu as :
ET ça :
?????
Si ton but est d'avoir des 1 ou des 0 en fonction des variables ....
il suffit d'écrire la récupération de tes variables ainsi :
Ensuite... tu as une erreur dans ta requête....
..... tu dois mettre après le VALUES ... les variables à insérer.....
....puis... tu dois choisir entre :
ET
...pas les deux !
Bref... une fois corrigé.. tu devrais avoir :
Le bloc TRY / CATCH permettant d'afficher le détail de l'erreur en cas de problème dans l'éxécution de la requête....
$lundi_matin = isset($_POST['lundi_matin']) ? $_POST['lundi_matin'] : ''; $mardi_matin = isset($_POST['mardi_matin']) ? $_POST['mardi_matin'] : ''; $mercredi_matin = isset($_POST['mercredi_matin']) ? $_POST['mercredi_matin'] : ''; $jeudi_matin = isset($_POST['jeudi_matin']) ? $_POST['jeudi_matin'] : ''; $vendredi_matin = isset($_POST['vendredi_matin']) ? $_POST['vendredi_matin'] : ''; $lundi_soir = isset($_POST['lundi_soir']) ? $_POST['lundi_soir'] : ''; $mardi_soir = isset($_POST['mardi_soir']) ? $_POST['mardi_soir'] : ''; $mercredi_soir = isset($_POST['mercredi_soir']) ? $_POST['mercredi_soir'] : ''; $jeudi_soir = isset($_POST['jeudi_soir']) ? $_POST['jeudi_soir'] : ''; $vendredi_soir = isset($_POST['vendredi_soir']) ? $_POST['vendredi_soir'] : '';
ET ça :
if (isset($_POST['lundi_matin'])) {
$lundi_matin = 1;
} else {
$lundi_matin = 0;
}
if (isset($_POST['lundi_soir'])) {
$lundi_soir = 1;
} else {
$lundi_soir = 0;
}
if (isset($_POST['mardi_matin'])) {
$mardi_matin = 1;
} else {
$mardi_matin = 0;
}
if (isset($_POST['mardi_soir'])) {
$mardi_soir = 1;
} else {
$mardi_soir = 0;
}
if (isset($_POST['mercredi_matin'])) {
$mercredi_matin = 1;
} else {
$mercredi_matin = 0;
}
if (isset($_POST['mercredi_soir'])) {
$mercredi_soir = 1;
} else {
$mercredi_soir = 0;
}
if (isset($_POST['jeudi_matin'])) {
$jeudi_matin = 1;
} else {
$jeudi_matin = 0;
}
if (isset($_POST['jeudi_soir'])) {
$jeudi_soir = 1;
} else {
$jeudi_soir = 0;
}
if (isset($_POST['vendredi_matin'])) {
$vendredi_matin = 1;
} else {
$vendredi_matin = 0;
}
if (isset($_POST['vendredi_soir'])) {
$vendredi_soir = 1;
} else {
$vendredi_soir = 0;
}
?????
Si ton but est d'avoir des 1 ou des 0 en fonction des variables ....
il suffit d'écrire la récupération de tes variables ainsi :
$lundi_matin = isset($_POST['lundi_matin']) ? 1 : 0; $mardi_matin = isset($_POST['mardi_matin']) ? 1 : 0; $mercredi_matin = isset($_POST['mercredi_matin']) ? 1 : 0; $jeudi_matin = isset($_POST['jeudi_matin']) ? 1 : 0; $vendredi_matin = isset($_POST['vendredi_matin'])? 1 : 0; $lundi_soir = isset($_POST['lundi_soir']) ? 1 : 0; $mardi_soir = isset($_POST['mardi_soir']) ? 1 : 0; $mercredi_soir = isset($_POST['mercredi_soir']) ? 1 : 0; $jeudi_soir = isset($_POST['jeudi_soir']) ? 1 : 0; $vendredi_soir = isset($_POST['vendredi_soir']) ? 1 : 0;
Ensuite... tu as une erreur dans ta requête....
$req = 'INSERT INTO garderie (lundi_matin, lundi_soir, mardi_matin, mardi_soir, mercredi_matin, mercredi_soir, jeudi_matin, jeudi_soir, vendredi_matin, vendredi_soir)
VALUES = ""';
..... tu dois mettre après le VALUES ... les variables à insérer.....
....puis... tu dois choisir entre :
$stmt->bindParam(':lundi_matin',$lundi_matin);
$stmt->bindParam(':lundi_soir',$lundi_soir);
$stmt->bindParam(':mardi_matin',$mardi_matin);
$stmt->bindParam(':mardi_soir',$mardi_soir);
$stmt->bindParam(':mercredi_matin',$mercredi_matin);
$stmt->bindParam(':mercredi_soir',$mercredi_soir);
$stmt->bindParam(':jeudi_matin',$jeudi_matin);
$stmt->bindParam(':jeudi_soir',$jeudi_soir);
$stmt->bindParam(':vendredi_matin',$vendredi_matin);
$stmt->bindParam(':vendredi_soir',$vendredi_soir);
ET
$req = array(":lundi_matin"=> $lundi_matin,":lundi_soir"=> $lundi_soir,":mardi_matin"=> $mardi_matin, ":mardi_soir" => $mardi_soir, ":mercredi_matin" => $mercredi_soir, ":jeudi_matin" => $jeudi_matin, ":jeudi_soir" => $jeudi_soir, ":vendredi_matin" => $vendredi_matin, ":vendredi_soir" => $vendredi_soir);
...pas les deux !
Bref... une fois corrigé.. tu devrais avoir :
<?php
error_reporting(E_ALL);
//connexion à la BDD
require_once "cnxBDD.php";
//Récupération des variables
$lundi_matin = isset($_POST['lundi_matin']) ? 1 : 0;
$mardi_matin = isset($_POST['mardi_matin']) ? 1 : 0;
$mercredi_matin = isset($_POST['mercredi_matin']) ? 1 : 0;
$jeudi_matin = isset($_POST['jeudi_matin']) ? 1 : 0;
$vendredi_matin = isset($_POST['vendredi_matin'])? 1 : 0;
$lundi_soir = isset($_POST['lundi_soir']) ? 1 : 0;
$mardi_soir = isset($_POST['mardi_soir']) ? 1 : 0;
$mercredi_soir = isset($_POST['mercredi_soir']) ? 1 : 0;
$jeudi_soir = isset($_POST['jeudi_soir']) ? 1 : 0;
$vendredi_soir = isset($_POST['vendredi_soir']) ? 1 : 0;
try{
//preparation de la requete
$sql = "INSERT INTO garderie (lundi_matin, lundi_soir, mardi_matin, mardi_soir, mercredi_matin, mercredi_soir, jeudi_matin, jeudi_soir, vendredi_matin, vendredi_soir)
VALUES = (:lundi_matin, :lundi_soir, :mardi_matin, :mardi_soir, :mercredi_matin, :mercredi_soir, :jeudi_matin, :jeudi_soir, :vendredi_matin, :vendredi_soir)";
$a_data = array(":lundi_matin"=> $lundi_matin
,":lundi_soir"=> $lundi_soir
,":mardi_matin"=> $mardi_matin
, ":mardi_soir" => $mardi_soir
, ":mercredi_matin" => $mercredi_soir
, ":jeudi_matin" => $jeudi_matin
, ":jeudi_soir" => $jeudi_soir
, ":vendredi_matin" => $vendredi_matin
, ":vendredi_soir" => $vendredi_soir
, ":mercredi_soir" => $mercredi_soir);
//Exécution de la requête
$stmt = $bdd->prepare($sql);
$stmt->execute($a_data);
} catch (Exception $e){
//en cas de pb dans la requete
echo 'Erreur : ' . $e->getMessage());
echo "<br> Dans la requête :".$sql;
echo "<br> Variables :<br><pre>";
print_r($a_data);
echo "</pre>";
exit();
}
Le bloc TRY / CATCH permettant d'afficher le détail de l'erreur en cas de problème dans l'éxécution de la requête....
Merci pour l'aide, franchement je m'en sors pas...mais j'ai toujours ça :
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\Program Files\EasyPHP-DevServer-14.1VC9\data\localweb\projet\reservation_garderie.php on line 34
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\Program Files\EasyPHP-DevServer-14.1VC9\data\localweb\projet\reservation_garderie.php on line 34
error_reporting(E_ALL);
require_once "cnxBDD.php";
$lundi_matin = isset($_POST['lundi_matin']) ? 1 : 0;
$mardi_matin = isset($_POST['mardi_matin']) ? 1 : 0;
$mercredi_matin = isset($_POST['mercredi_matin']) ? 1 : 0;
$jeudi_matin = isset($_POST['jeudi_matin']) ? 1 : 0;
$vendredi_matin = isset($_POST['vendredi_matin'])? 1 : 0;
$lundi_soir = isset($_POST['lundi_soir']) ? 1 : 0;
$mardi_soir = isset($_POST['mardi_soir']) ? 1 : 0;
$mercredi_soir = isset($_POST['mercredi_soir']) ? 1 : 0;
$jeudi_soir = isset($_POST['jeudi_soir']) ? 1 : 0;
$vendredi_soir = isset($_POST['vendredi_soir']) ? 1 : 0;
try{
$sql = "INSERT INTO garderie (lundi_matin, lundi_soir, mardi_matin, mardi_soir, mercredi_matin, mercredi_soir, jeudi_matin, jeudi_soir, vendredi_matin, vendredi_soir)
VALUES = (:lundi_matin, :lundi_soir, :mardi_matin, :mardi_soir, :mercredi_matin, :mercredi_soir, :jeudi_matin, :jeudi_soir, :vendredi_matin, :vendredi_soir)";
$a_data = array(":lundi_matin"=> $lundi_matin
,":lundi_soir"=> $lundi_soir
,":mardi_matin"=> $mardi_matin
, ":mardi_soir" => $mardi_soir
, ":mercredi_matin" => $mercredi_matin
, ":mercredi_soir" => $mercredi_soir
, ":jeudi_matin" => $jeudi_matin
, ":jeudi_soir" => $jeudi_soir
, ":vendredi_matin" => $vendredi_matin
, ":vendredi_soir" => $vendredi_soir);
$stmt = $bdd->prepare($sql);
$stmt->execute($a_data);
print_r($a_data);
} catch (Exception $e){
echo 'Erreur : ' . $e->getMessage();
echo "<br> Dans la requête :".$sql;
echo "<br> Variables :<br><pre>";
print_r($a_data);
echo '$a_data';
echo "</pre>";
exit();
}
Essayes ça :
try{
$sql = "INSERT INTO garderie (lundi_matin, lundi_soir, mardi_matin, mardi_soir, mercredi_matin, mercredi_soir, jeudi_matin, jeudi_soir, vendredi_matin, vendredi_soir)
VALUES = (:lundi_matin, :lundi_soir, :mardi_matin, :mardi_soir, :mercredi_matin, :mercredi_soir, :jeudi_matin, :jeudi_soir, :vendredi_matin, :vendredi_soir)";
$a_data = array(":lundi_matin"=> $lundi_matin
,":lundi_soir"=> $lundi_soir
,":mardi_matin"=> $mardi_matin
, ":mardi_soir" => $mardi_soir
, ":mercredi_matin" => $mercredi_matin
, ":mercredi_soir" => $mercredi_soir
, ":jeudi_matin" => $jeudi_matin
, ":jeudi_soir" => $jeudi_soir
, ":vendredi_matin" => $vendredi_matin
, ":vendredi_soir" => $vendredi_soir);
$stmt = $bdd->prepare($sql);
$stmt->execute($a_data);
$id = $bdd->lastInsertId();
if($id){
echo "<br> Enregistrement effectué !. ID = ".$id;
}else{
echo "<br> Erreur lors de l'enregistrement !"
print_r($a_data);
}
} catch (Exception $e){
echo 'Erreur : ' . $e->getMessage();
echo "<br> Dans la requête :".$sql;
echo "<br> Variables :<br><pre>";
print_r($a_data);
echo '$a_data';
echo "</pre>";
exit();
}
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Salut, ça me fait ça :
Parse error: syntax error, unexpected '}', expecting ',' or ';' in C:\Program Files\EasyPHP-DevServer-14.1VC9\data\localweb\projet\reservation_garderie.php on line 44
Parse error: syntax error, unexpected '}', expecting ',' or ';' in C:\Program Files\EasyPHP-DevServer-14.1VC9\data\localweb\projet\reservation_garderie.php on line 44
error_reporting(E_ALL);
require_once "cnxBDD.php";
$lundi_matin = isset($_POST['lundi_matin']) ? 1 : 0;
$mardi_matin = isset($_POST['mardi_matin']) ? 1 : 0;
$mercredi_matin = isset($_POST['mercredi_matin']) ? 1 : 0;
$jeudi_matin = isset($_POST['jeudi_matin']) ? 1 : 0;
$vendredi_matin = isset($_POST['vendredi_matin'])? 1 : 0;
$lundi_soir = isset($_POST['lundi_soir']) ? 1 : 0;
$mardi_soir = isset($_POST['mardi_soir']) ? 1 : 0;
$mercredi_soir = isset($_POST['mercredi_soir']) ? 1 : 0;
$jeudi_soir = isset($_POST['jeudi_soir']) ? 1 : 0;
$vendredi_soir = isset($_POST['vendredi_soir']) ? 1 : 0;
try{
$sql = "INSERT INTO garderie (lundi_matin, lundi_soir, mardi_matin, mardi_soir, mercredi_matin, mercredi_soir, jeudi_matin, jeudi_soir, vendredi_matin, vendredi_soir)
VALUES = (:lundi_matin, :lundi_soir, :mardi_matin, :mardi_soir, :mercredi_matin, :mercredi_soir, :jeudi_matin, :jeudi_soir, :vendredi_matin, :vendredi_soir)";
$a_data = array(":lundi_matin"=> $lundi_matin
,":lundi_soir"=> $lundi_soir
,":mardi_matin"=> $mardi_matin
, ":mardi_soir" => $mardi_soir
, ":mercredi_matin" => $mercredi_matin
, ":mercredi_soir" => $mercredi_soir
, ":jeudi_matin" => $jeudi_matin
, ":jeudi_soir" => $jeudi_soir
, ":vendredi_matin" => $vendredi_matin
, ":vendredi_soir" => $vendredi_soir);
$stmt = $bdd->prepare($sql);
$stmt->execute($a_data);
$id = $bdd->lastInsertId();
if($id){
echo "<br> Enregistrement effectué !. ID = ".$id;
}else{
echo "<br> Erreur lors de l'enregistrement !";
//print_r($a_data);
} catch (Exception $e){
echo 'Erreur : ' . $e->getMessage();
echo "<br> Dans la requête :".$sql;
echo "<br> Variables :<br><pre>";
print_r($a_data);
echo '$a_data';
echo "</pre>";
exit();
}
Non pas possible ...
le code que toi tu nous montres contient une erreur ... ( une accolade manquante après le if / else ) ... accolade pourtant présente dans le code que je t'ai donné.
le code que toi tu nous montres contient une erreur ... ( une accolade manquante après le if / else ) ... accolade pourtant présente dans le code que je t'ai donné.
<?php
try{
$sql = "INSERT INTO garderie (lundi_matin, lundi_soir, mardi_matin, mardi_soir, mercredi_matin, mercredi_soir, jeudi_matin, jeudi_soir, vendredi_matin, vendredi_soir)
VALUES = (:lundi_matin, :lundi_soir, :mardi_matin, :mardi_soir, :mercredi_matin, :mercredi_soir, :jeudi_matin, :jeudi_soir, :vendredi_matin, :vendredi_soir)";
$a_data = array(":lundi_matin"=> $lundi_matin
,":lundi_soir"=> $lundi_soir
,":mardi_matin"=> $mardi_matin
, ":mardi_soir" => $mardi_soir
, ":mercredi_matin" => $mercredi_matin
, ":mercredi_soir" => $mercredi_soir
, ":jeudi_matin" => $jeudi_matin
, ":jeudi_soir" => $jeudi_soir
, ":vendredi_matin" => $vendredi_matin
, ":vendredi_soir" => $vendredi_soir
);
$stmt = $bdd->prepare($sql);
$stmt->execute($a_data);
$id = $bdd->lastInsertId();
if($id){
echo "<br> Enregistrement effectué !. ID = ".$id;
}else{
echo "<br> Erreur lors de l'enregistrement !";
print_r($a_data);
}
} catch (Exception $e){
echo 'Erreur : ' . $e->getMessage();
echo "<br> Dans la requête :".$sql;
echo "<br> Variables :<br><pre>";
print_r($a_data);
echo '$a_data';
echo "</pre>";
exit();
}
Et donc... sans le "=" en trop ... le code serait :
try{
$sql = "INSERT INTO garderie (lundi_matin, lundi_soir, mardi_matin, mardi_soir, mercredi_matin, mercredi_soir, jeudi_matin, jeudi_soir, vendredi_matin, vendredi_soir)
VALUES (:lundi_matin, :lundi_soir, :mardi_matin, :mardi_soir, :mercredi_matin, :mercredi_soir, :jeudi_matin, :jeudi_soir, :vendredi_matin, :vendredi_soir)";
$a_data = array(":lundi_matin"=> $lundi_matin
,":lundi_soir"=> $lundi_soir
,":mardi_matin"=> $mardi_matin
, ":mardi_soir" => $mardi_soir
, ":mercredi_matin" => $mercredi_matin
, ":mercredi_soir" => $mercredi_soir
, ":jeudi_matin" => $jeudi_matin
, ":jeudi_soir" => $jeudi_soir
, ":vendredi_matin" => $vendredi_matin
, ":vendredi_soir" => $vendredi_soir
);
$stmt = $bdd->prepare($sql);
$stmt->execute($a_data);
$id = $bdd->lastInsertId();
if($id){
echo "<br> Enregistrement effectué !. ID = ".$id;
}else{
echo "<br> Erreur lors de l'enregistrement !";
print_r($a_data);
}
} catch (Exception $e){
echo 'Erreur : ' . $e->getMessage();
echo "<br> Dans la requête :".$sql;
echo "<br> Variables :<br><pre>";
print_r($a_data);
echo '$a_data';
echo "</pre>";
exit();
}
J'ai un petit problème avec un bouton de redirection, j'aimerai quand on clique sur le bouton Enregistrer la page d'après soit index2.html
De la page connexion vers index2
Voici les codes de connexion.html :
connexion.php :
De la page connexion vers index2
Voici les codes de connexion.html :
<head>
<meta charset="utf-8" />
</head>
<body>
<form method="POST" action="connexion.php">
<p>
<label for="username">Pseudo :</label>
<input type="text" name="username" id="username" />
<br></br>
<label for="password">Mot de passe :</label>
<input type="text" name="password" id="password" />
<br></br>
<label for="password2"> Retapez votre mot de passe :</label>
<input type="text" name="password2" id="password2" />
<br></br>
<input type="submit" name="submit" value="Envoyer" >
</p>
</form>
</body>
connexion.php :
error_reporting(E_ALL);
if(isset($_POST['submit']))
{
$username =htmlentities(trim($_POST['username']));
$password =htmlentities(trim($_POST['password']));
$password2 =htmlentities(trim($_POST['password2']));
if($username&&$password&&$password2)
{
if($password==$password2)
{
$password = md5($password);
$bdd = new PDO('mysql:host=localhost;dbname=projet;charset=utf8', 'root', '');
try
{
$bdd = new PDO('mysql:host=localhost;dbname=projet;charset=utf8', 'root', '');
}
catch (Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
mysql_select_db('projet');
$reg = mysql_query("SELECT * FROM connexion WHERE username='$username'");
$req = $bdd->prepare("INSERT INTO connexion (username, password) VALUES (:username, :password)");
$req->execute(array("username" => $username, "password" => $password));
die("Inscription terminée <ahref=connexion.php connectez</a>vous");
}else echo"Ce pseudo n'est pas disponible";
}else echo "Les deux passwords doivent être identiques";
};