Transfert valeur checkbox vers un autre fichier
Posté : 24 févr. 2015, 20:01
Bonjour à toutes et à tous, je n'arrive pas à récupérer les valeurs de cases cochées dans un autre fichier avec $_SESSION. Le résultat attendu dans le fichier 2 reste désespéremment vide. Voici ce que j'ai bidouillé:
Fichier 1:
<?php
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Document sans titre</title>
</head>
<body>
<form action="tft_var.php" method="post">
<input type="checkbox" name="nombre[]" value="Un"><label>Un</label><br/>
<input type="checkbox" name="nombre[]" value="Deux"><label>Deux</label><br/>
<input type="submit" name="envoyer" value="Envoyer"/>
</form>
<?php
if(isset($_POST['envoyer'])){
if(!empty($_POST['nombre'])){
foreach($_POST['nombre'] as $selection){
}
}
}
$_SESSION['nombre'] = $selection;
?>
</body>
</html>
Fichier 2:
<?php
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Document sans titre</title>
</head>
<body>
<?php
$selection = $_SESSION['nombre'];
echo "Nombre(s) choisi (s) ".$_SESSION['nombre'];
?>
</body>
</html>
Merci pour vos lumières.
Fichier 1:
<?php
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Document sans titre</title>
</head>
<body>
<form action="tft_var.php" method="post">
<input type="checkbox" name="nombre[]" value="Un"><label>Un</label><br/>
<input type="checkbox" name="nombre[]" value="Deux"><label>Deux</label><br/>
<input type="submit" name="envoyer" value="Envoyer"/>
</form>
<?php
if(isset($_POST['envoyer'])){
if(!empty($_POST['nombre'])){
foreach($_POST['nombre'] as $selection){
}
}
}
$_SESSION['nombre'] = $selection;
?>
</body>
</html>
Fichier 2:
<?php
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Document sans titre</title>
</head>
<body>
<?php
$selection = $_SESSION['nombre'];
echo "Nombre(s) choisi (s) ".$_SESSION['nombre'];
?>
</body>
</html>
Merci pour vos lumières.