我有三页,当我单击第一个上的按钮时,我转到第二个页面,而当我单击第二个中的另一个按钮时,我转到了第三页。然后,当我单击第三个按钮时,我回到第二个按钮 每次我转到第三页时,都会增加一个变量,但是当我返回第二页时,即使我将变量发回并递增到第二页,该变量仍与我进入第二页之前的变量相同。第三页。
第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>
答案 0 :(得分:0)
在page2上,您没有传递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.'" />