如何在我循环的两个页面之间递增变量

How to increment a variable between two pages in which I loop

我有三个页面,当我单击第一个页面上的一个按钮时,我转到第二个页面,当我单击第二个页面上的另一个按钮时,我转到第三个页面。然后,当我点击第三个按钮时,我回到第二个 有一个变量,我每次转到第三页时都会递增,但是当我返回第二页时,即使我将变量发回并递增到第二页,该变量仍然与我去之前一样第三页.

第 1 页:

<head>
<meta charset="utf-8" />
<title> Evaluation des enseignements </title>
<link rel="stylesheet" type="text/css" name="style_telecommande.css" > 
</head>

<body>
<header>
<h1> Site de vote </h1>
<h2> Bienvenue sur le site d'évaluation des enseignements </h2>
</header>
<p> Entrez votre numéro étudiant INE </p>
<form action="page-vote.php" method="post">

<input type="text" name="numero" value="" id="num_etu" />

<label> Votre nom: </label>: <input type="text" name="name" value="" id="nom" >
<label> Votre prenom </label>: <input type="text" name="validation" value="" id="ok" />
<input type="submit" name="ok" id="entree" value="Valider" />

</form>

</body>

第 2 页:

<head>

<link rel= name="style-telecommande.css" type="text/css" >
<title> Telecommande de vote </title>
<meta charset="utf-8" />
</head>

<body>
<header> 
<h1> Site de vote </h1>
<h2> Télécommande de vote </h2>
</header>
<?php
if (isset($_POST["num_question"]))
{
//here is the instruction executed when I come from the third page, the variable doesn't correspond to what I sent
$question_pg_vote= max(1, min(20,(int) ($_POST["num_question"])));

echo $question_pg_vote;
echo 'yes';
}
else {
//here is the instruction executed when I come from the first page, everything works until then
    echo 'nope';
    $question_pg_vote=1;
}
//echo '<p> question numéro '.$question.' </p>';
echo'
<form action="page_validation.php" method="post">
<input type="submit" name="reponse1" value="A" />
<input type="submit" name="reponse2" value="B" />
<input type="submit" name="reponse3" value="C" />
<input type="submit" name="reponse4" value="D" />
<input type="submit" name="reponse5" value="E" />
<input type="hidden" name="numero_question" value="question_pg_vote" />
</form>
';
?>

</body>

第 3 页:

<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=bdd projet s8;charset=utf8','root','');
}
catch (Exception $e) 
{
    die('Erreur : ' .$e->getMessage());
}
$question= (int) max (1,min(20, ($_POST['numero_question'])))+1;
//echo (int) max (1,min(20, ($_POST["numero_question"])));
if(isset($_POST['reponse1']))
{
$vote=$_POST['reponse1'];
}
if(isset($_POST['reponse2']))
{
$vote=$_POST['reponse2'];
}
if(isset($_POST['reponse3']))
{
$vote=$_POST['reponse3'];
}
if(isset($_POST['reponse4']))
{
$vote=$_POST['reponse4'];
}
if(isset($_POST['reponse5']))
{
$vote=$_POST['reponse5'];
}
// the 12 second lines are for adding data into my database, don't pay attention to them
/*if ($question==1)
{
$id= random_int;
}*/
$reponse = $bdd->prepare('INSERT INTO reponse(id_question,id_votant,reponse_votant) VALUES(:question1,\'1\',:reponse_votant)');
$reponse->execute(array(
'reponse_votant' => $vote
,'question1' => $question
//,'id_user' => $id 
));
echo'
<form action="page-vote.php" method="post">
<input type="submit" name="retour" value="return" />
<input type="hidden" name="num_question" value="question" />
</form>
<p> question '.$question.' </p>
//the line before displays the variable and I can see it has been incremented
';
?>
</body>

在第 2 页上,您没有传递 PHP 变量值

<input type="hidden" name="numero_question" value="question_pg_vote" />

应该是:

<input type="hidden" name="numero_question" value="'.$question_pg_vote.'" />

第 3 页相同

 <input type="hidden" name="num_question" value="question" />

应该是:

<input type="hidden" name="num_question" value="'.$question.'" />