par
Weppes41 » 16 mai 2012, 15:10
Bonjour a tous,
J'ai créé un formulaire, dedans il y a des 6 additions, lors de la première affichage de la page je souhaites créer des variables aléatoires. Mais si je reviens sur cette page, je veux garder les nombres que j'avais créé, est ce possible ?
Une fois que j'ai mes opérations faites, il faut que je les sauvegardes, comment faire ? (Les variables de sessions ne fonctionnent pas.. peut être parce que je code sur une page simple ?)
voici le code:
function my_rand(){
$temp_rand=rand(5,15);
return $temp_rand;
}
if(isset($_GET['exo1a']) &&
isset($_GET['exo1b']) &&
isset($_GET['exo1c']) &&
isset($_GET['exo1d']) &&
isset($_GET['exo1e']) &&
isset($_GET['exo1f'])
){
echo "<pre>";
print_r($_SESSION['Exo1']);
echo "</pre>";
$nb1=$_SESSION['Exo1'][1];
$nb2=$_SESSION['Exo1'][2];
$nb3=$_SESSION['Exo1'][3];
$nb4=$_SESSION['Exo1'][4];
$nb5=$_SESSION['Exo1'][5];
$nb6=$_SESSION['Exo1'][6];
$nb7=$_SESSION['Exo1'][7];
$nb8=$_SESSION['Exo1'][8];
$nb9=$_SESSION['Exo1'][9];
$nb10=$_SESSION['Exo1'][10];
$nb11=$_SESSION['Exo1'][11];
$nb12=$_SESSION['Exo1'][12];
}
else{
$nb1=my_rand();
$nb2=my_rand()
$nb3=my_rand();
$nb4=my_rand();
$nb5=my_rand();
$nb6=my_rand();
$nb7=my_rand();
$nb8=my_rand();
$nb9=my_rand();
$nb10=my_rand();
;$nb11=my_rand();
$nb12=my_rand();
}
$calcul="<form method=\"POST\" name='calcul'>";
$calcul.="<TABLE ><TR>";
$calcul.="<p id=niveau > <u>Niveau 1</u> : </p>";
$calcul.="<TH>"."<label for=\"1\"> ".$nb1." + ".$nb2. " = "."</label><input type=\"text\" name=\"exo1a\" id=\"1\"></TH>";
$calcul.="<TH>"."<label for=\"1\"> ".$nb3." + ".$nb4. " = "."</label><input type=\"text\" name=\"exo1b\" id=\"1\"></TH>";
$calcul.="<TH>"."<label for=\"1\"> ".$nb5." + ".$nb6. " = "."</label><input type=\"text\" name=\"exo1c\" id=\"1\"></TH>";
$calcul.="</TR></TABLE >";
$calcul.="<br>";
$calcul.="<TABLE ><TR>";
$calcul.="<p id=niveau > <u>Niveau 2</u> : </p>";
$calcul.="<TH>"."<label for=\"1\"> ".$nb7." + ".$nb8. " = "."</label><input type=\"text\" name=\"exo1d\" id=\"1\"></TH>";
$calcul.="<TH>"."<label for=\"1\"> ".$nb9." + ".$nb10. " = "."</label><input type=\"text\" name=\"exo1e\" id=\"1\"></TH>";
$calcul.="<TH>"."<label for=\"1\"> ".$nb11." + ".$nb12. " = "."</label><input type=\"text\" name=\"exo1f\" id=\"1\"></TH>";
$calcul.="</TR></TABLE >";
$calcul.="<br>";
$calcul.="<br>";
$calcul.="<TABLE ><TR>";
$calcul.="<TD COLSPAN=2>";
$calcul.="<INPUT name='envoie' id=\"input_exo1\" type=\"submit\" value=\"Envoyer\">";
$calcul.="</TD>";
$calcul.="</TR></TABLE >";
$calcul.="<form>";
$tab_nombre[0]=$nb1;
$tab_nombre[1]=$nb2;
$tab_nombre[2]=$nb3;
$tab_nombre[3]=$nb4;
$tab_nombre[4]=$nb5;
$tab_nombre[5]=$nb6;
$tab_nombre[6]=$nb7;
$tab_nombre[7]=$nb8;
$tab_nombre[8]=$nb9;
$tab_nombre[9]=$nb10;
$tab_nombre[10]=$nb11;
$tab_nombre[11]=$nb12;
$_SESSION['Exo1']=$tab_nombre;
echo "<pre>";
print_r($_SESSION['Exo1']);
echo "</pre>";
echo $calcul;
Bonjour a tous,
J'ai créé un formulaire, dedans il y a des 6 additions, lors de la première affichage de la page je souhaites créer des variables aléatoires. Mais si je reviens sur cette page, je veux garder les nombres que j'avais créé, est ce possible ?
Une fois que j'ai mes opérations faites, il faut que je les sauvegardes, comment faire ? (Les variables de sessions ne fonctionnent pas.. peut être parce que je code sur une page simple ?)
voici le code:
[php]
function my_rand(){
$temp_rand=rand(5,15);
return $temp_rand;
}
if(isset($_GET['exo1a']) &&
isset($_GET['exo1b']) &&
isset($_GET['exo1c']) &&
isset($_GET['exo1d']) &&
isset($_GET['exo1e']) &&
isset($_GET['exo1f'])
){
echo "<pre>";
print_r($_SESSION['Exo1']);
echo "</pre>";
$nb1=$_SESSION['Exo1'][1];
$nb2=$_SESSION['Exo1'][2];
$nb3=$_SESSION['Exo1'][3];
$nb4=$_SESSION['Exo1'][4];
$nb5=$_SESSION['Exo1'][5];
$nb6=$_SESSION['Exo1'][6];
$nb7=$_SESSION['Exo1'][7];
$nb8=$_SESSION['Exo1'][8];
$nb9=$_SESSION['Exo1'][9];
$nb10=$_SESSION['Exo1'][10];
$nb11=$_SESSION['Exo1'][11];
$nb12=$_SESSION['Exo1'][12];
}
else{
$nb1=my_rand();
$nb2=my_rand()
$nb3=my_rand();
$nb4=my_rand();
$nb5=my_rand();
$nb6=my_rand();
$nb7=my_rand();
$nb8=my_rand();
$nb9=my_rand();
$nb10=my_rand();
;$nb11=my_rand();
$nb12=my_rand();
}
$calcul="<form method=\"POST\" name='calcul'>";
$calcul.="<TABLE ><TR>";
$calcul.="<p id=niveau > <u>Niveau 1</u> : </p>";
$calcul.="<TH>"."<label for=\"1\"> ".$nb1." + ".$nb2. " = "."</label><input type=\"text\" name=\"exo1a\" id=\"1\"></TH>";
$calcul.="<TH>"."<label for=\"1\"> ".$nb3." + ".$nb4. " = "."</label><input type=\"text\" name=\"exo1b\" id=\"1\"></TH>";
$calcul.="<TH>"."<label for=\"1\"> ".$nb5." + ".$nb6. " = "."</label><input type=\"text\" name=\"exo1c\" id=\"1\"></TH>";
$calcul.="</TR></TABLE >";
$calcul.="<br>";
$calcul.="<TABLE ><TR>";
$calcul.="<p id=niveau > <u>Niveau 2</u> : </p>";
$calcul.="<TH>"."<label for=\"1\"> ".$nb7." + ".$nb8. " = "."</label><input type=\"text\" name=\"exo1d\" id=\"1\"></TH>";
$calcul.="<TH>"."<label for=\"1\"> ".$nb9." + ".$nb10. " = "."</label><input type=\"text\" name=\"exo1e\" id=\"1\"></TH>";
$calcul.="<TH>"."<label for=\"1\"> ".$nb11." + ".$nb12. " = "."</label><input type=\"text\" name=\"exo1f\" id=\"1\"></TH>";
$calcul.="</TR></TABLE >";
$calcul.="<br>";
$calcul.="<br>";
$calcul.="<TABLE ><TR>";
$calcul.="<TD COLSPAN=2>";
$calcul.="<INPUT name='envoie' id=\"input_exo1\" type=\"submit\" value=\"Envoyer\">";
$calcul.="</TD>";
$calcul.="</TR></TABLE >";
$calcul.="<form>";
$tab_nombre[0]=$nb1;
$tab_nombre[1]=$nb2;
$tab_nombre[2]=$nb3;
$tab_nombre[3]=$nb4;
$tab_nombre[4]=$nb5;
$tab_nombre[5]=$nb6;
$tab_nombre[6]=$nb7;
$tab_nombre[7]=$nb8;
$tab_nombre[8]=$nb9;
$tab_nombre[9]=$nb10;
$tab_nombre[10]=$nb11;
$tab_nombre[11]=$nb12;
$_SESSION['Exo1']=$tab_nombre;
echo "<pre>";
print_r($_SESSION['Exo1']);
echo "</pre>";
echo $calcul;[/php]