I initialize my $_SESSION
var but I have these errors when I launch the index without submit the form:
if(!empty($_POST)){
$_SESSION['idZone'] = 0;
$_SESSION['idSalle'] = 0;
$_SESSION['idUtilisateur'] = 0;
$_SESSION['dateDebut'] = 0 ;
$_SESSION['dateFin'] = 0;
}
?>
This is my full code :
<?php
include('fonctionsBDD.php');
$bdd = connectionBDD();
session_start();
if(!empty($_POST)){
$_SESSION['idZone'] = 0;
$_SESSION['idSalle'] = 0;
$_SESSION['idUtilisateur'] = 0;
$_SESSION['dateDebut'] = 0 ;
$_SESSION['dateFin'] = 0;
}
?>
<!-- Choix des filtres à afficher -->
<p>Quels filtres afficher ?</p>
<form action="" method="POST">
<input type="checkbox" name="cbx-zones">Zones</input>
<input type="checkbox" mname="cbx-salles">Salles</input>
<input type="checkbox" name="cbx-dates">Date</input>
<input type="checkbox" name="cbx-heures">Heures</input>
<p><input type="submit" /></p>
</form>
<!-- Zone filtres -->
<div class="FiltreSalle">
<form action="" method="POST">
<?php
if (isset($_POST['cbx-zones'])) {
/* COntenu d'un filtre ici */
}
?>
<!-- Filtre par Area Name-->
<form action="" method="POST">
<br /><br />
<label>Choisir la zone </label><br />
<select name="zone">
<?php echo "<option unselected>- - - Choisissez une zone - - - </option>
";
$reponseSalle = $bdd->query('SELECT * FROM mrbs_area ORDER BY area_name');
while ($donnees = $reponseSalle->fetch(PDO::FETCH_OBJ)) {
?>
<option value="<?php echo $donnees->id; ?>"> <?php echo $donnees->area_name; ?></option>
<?php
}
?>
</select>
<!-- Filtre par salle -->
<br /><br />
<label>Choisir la salle</label><br />
<select name="salle">
<?php echo "<option unselected>- - - Choisissez une salle - - - </option>
";
$reponseSalle = $bdd->query('SELECT * FROM mrbs_room ORDER BY room_name');
while ($donnees = $reponseSalle->fetch(PDO::FETCH_OBJ)) {
?>
<option value="<?php echo $donnees->id; ?>"> <?php echo $donnees->room_name; ?></option>
<?php
}
?>
</select>
<!-- Filtre par utilisateurs-->
<br /><br />
<label>Choisir l'utilisateur</label><br />
<select name="utilisateur">
<?php echo "<option unselected>- - - Choisissez un utilisateur - - - </option>
";
$reponseSalle = $bdd->query('SELECT * FROM mrbs_users ORDER BY name');
while ($donnees = $reponseSalle->fetch(PDO::FETCH_OBJ)) {
?>
<option value="<?php echo $donnees->id; ?>"> <?php echo $donnees->name; ?></option>
<?php
}
?>
</select>
<!-- Filtres par DatePicker -->
<br /> <br />
<script>
$(function() {
$("#from").datepicker({
defaultDate: "+1d",
changeMonth: true,
numberOfMonths: 1,
dateFormat : '@',
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
$("#to").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat : '@',
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
var currentDate = $( ".selector" ).datepicker( "getDate" );
}
});
});
</script>
<label for="from">Du</label>
<input type="text" id="from" name="from">
<label for="to">Au</label>
<input type="text" id="to" name="to">
<input type='submit' value='Submit'><br /><br />
</form>
<!-- Traitement des données -->
<?php
$_SESSION['idZone'] = $_POST['zone'];
$_SESSION['idSalle'] = $_POST['salle'];
$_SESSION['idUtilisateur'] = $_POST['utilisateur'];
$_SESSION['dateDebut'] = $_POST["from"];
$_SESSION['dateFin'] = $_POST["to"];
echo('La zone séléctionnée est :' . $_SESSION['idZone'] . '<br />');
echo('La salle séléctionnée est :' . $_SESSION['idSalle'] . '<br />');
echo('L utilisateur séléctionné est :' . $_SESSION['idUtilisateur'] . '<br />');
echo('La date de début séléctionnée est :' . $_SESSION['dateDebut'] . '<br />');
echo('La date de fin séléctionnée est :' . $_SESSION['dateFin'] . '<br />');
?>
I think my initialization ins't good but I do not know why. If anyone can help me :)