Pb checkbox retour valeur

Résolu/Fermé
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016 - 5 févr. 2016 à 09:03
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 - 9 févr. 2016 à 11:55
Bonjour, j'ai une eptite erreur dans mon code que j'arrive pas à déceler :

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


9 réponses

jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
5 févr. 2016 à 10:52
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 :
$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 )


0
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
5 févr. 2016 à 10:59
En modifiant les variables, j'ai rien en enregistrement.
0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
5 févr. 2016 à 11:01
Montre le code corrigé.
0
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
5 févr. 2016 à 11:03

 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();
0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
Modifié par jordane45 le 5/02/2016 à 13:12
Pourquoi est-ce que tu as :
$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....
0
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
5 févr. 2016 à 11:20
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
0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649 > lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
5 févr. 2016 à 11:22
Compare la requête avec le nombre de variables dans l'Array. .. tu verras qu'il en manque une...
mercredi_soir ...
0
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
5 févr. 2016 à 11:25
Merci j'ai rajouter, il valide mais toujours pas d'enregistrements.
0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
5 févr. 2016 à 12:54
Il valide ... c'est à dire ?

Tu peux faire un print de $a_data pour voir ce qu'il contient ??
0
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
5 févr. 2016 à 13:38
Quand je fais un print de a_data y'a rien qui s'affiche.
0
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
5 févr. 2016 à 13:55
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();
}
0
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
5 févr. 2016 à 13:55
Il affiche ça :

Array ( [:lundi_matin] => 0 [:lundi_soir] => 0 [:mardi_matin] => 0 [:mardi_soir] => 0 [:mercredi_matin] => 0 [:mercredi_soir] => 0 [:jeudi_matin] => 1 [:jeudi_soir] => 1 [:vendredi_matin] => 0 [:vendredi_soir] => 0 )
0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
5 févr. 2016 à 16:11
Donc tu as bien les bonnes valeurs....
alors qu'est ce qui ne marche pas ??
0
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
5 févr. 2016 à 16:14
Oui j'ai les bonnes valeurs mais elles s'enregistrent pas dans la table.
0
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
8 févr. 2016 à 13:56
?
0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
8 févr. 2016 à 16:04
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();
}

0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
Modifié par jordane45 le 9/02/2016 à 10:09
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


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();
}
0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
9 févr. 2016 à 09:09
Tu n'es pas capable de fqire un coper/coller du code que je t'ai donné sans faire d'erreur ?? Oo
0
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
9 févr. 2016 à 10:03
En copiant collant ton code, il y a cette erreur.
0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649 > lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
Modifié par jordane45 le 9/02/2016 à 10:09
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é.

<?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();
}
0
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
9 févr. 2016 à 10:11
Le code passe mais à l'éxécution il me met :

Erreur lors de l'enregistrement !Array ( [:lundi_matin] => 1 [:lundi_soir] => 0 [:mardi_matin] => 0 [:mardi_soir] => 1 [:mercredi_matin] => 0 [:mercredi_soir] => 0 [:jeudi_matin] => 0 [:jeudi_soir] => 0 [:vendredi_matin] => 0 [:vendredi_soir] => 0 )
0
Thorak83 Messages postés 1051 Date d'inscription jeudi 20 juin 2013 Statut Membre Dernière intervention 22 décembre 2017 156
9 févr. 2016 à 10:17
Juste par curiosité, le champ ID est un champ auto incrémenté ? ou pas.
0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
9 févr. 2016 à 10:30
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();
}

0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
9 févr. 2016 à 10:31
Je ne l'avais pas vu en recopiant ton code..... :-(
0
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
9 févr. 2016 à 10:34
Merci pour l'aide c'est super sympa !
0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
9 févr. 2016 à 10:35
Si la question est résolue..
Merci de ne pas oublier de clôturer le sujet
(en cliquant sur le lien "Marquer comme résolu" qui se trouve sous le titre de la question)

Cordialement,
Jordane
0
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
9 févr. 2016 à 10:39
Par contre j'ai un autre petit problème, vous pouvez regarder ?
0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
9 févr. 2016 à 11:55

j'ai un autre petit problème

Autre Problème = Ouverture NOUVELLE discussion. (après avoir mis celle la en résulue )
cela facilite la recherche sur le forum.

Merci.
0
lecjoh59 Messages postés 82 Date d'inscription lundi 1 février 2016 Statut Membre Dernière intervention 12 février 2016
9 févr. 2016 à 11:08
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 :

<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";
	};	
0