美好的一天,我有一个从数据库中获取其值的表单,
<?php
$questionId = 1;
$pdo = new PDO("mysql:host=localhost;dbname=mydb", 'root', '');
$sth = $pdo->prepare("SELECT * FROM questions WHERE questionid = $questionId");
$sth->execute();
while ($row = $sth->fetch()):
?>
<form action="exam1.php" method="POST">
<?php echo "<h4>".$row['instructions'] ."</h4><br>"; ?><h4><?php echo $questionId. ". ".$row['name']; ?></h4>
<input type="radio" name="choices" id="choices" value="<?php echo $row['choice1']; ?>"><?php echo $row['choice1']; ?> ...(other choices)
<input type="submit" name="submitAnswers">
</form>
<?php endwhile;?>
我想要的是在提交表单后如何增加$questionId
变量。我试过这个
if (isset($_GET['choices'])) {
echo $_GET['choices'];
$questionId = $questionId + 1;
}
问题ID已更新,但只是一次。 我需要它总是通过添加1来更新。
答案 0 :(得分:0)
<form method="post" >
<input type="submit" name="submit">
</form>
<?php
session_start();
$_SESSION['id'];
if (isset($_POST['submit'])) {
$_SESSION['id']=$_SESSION['id']+1;
}
echo "Value is => ",$_SESSION['id'],"<br>";
?>