我正在为网站构建一个基于 php 的测验。我是初学者。我编写了从数据库中获取问题和选项的代码,并将它们显示在我的页面中。当用户选择选项时,我希望将答案插入到我的数据库中。我写了一些基本代码,但它不起作用请帮助。这是我的代码问题表有 7rows(qid,question,optiona,optionb,optionc,optiond,answeroption),答案表有 simple2rows(qid,answer)
if(isset($_POST['next']))
{
$a=$_POST['a'];
}
if(!isset($a))
{
$a=0;
}
include('connection.php');
mysql_query("INSERT INTO answers (username,qid, option)
VALUES ($username,a-1,'$_POST('option'))");
$sql1="SELECT * FROM exam1 LIMIT 1 OFFSET $a";
$result=mysql_query($sql1);
echo "<form method='post' action='quiz.php'>";
while ($row = mysql_fetch_array($result))
{
echo $row['question']. "<br/>";
echo "<input type='radio' value='optiona' name='option'>" .$row['optiona'];
echo "<input type='radio' value='optionb' name='option'>" .$row['optionb'];
echo "<input type='radio' value='optionc' name='option'>" .$row['optionc'];
echo "<input type='radio' value='optiond' name='option'>" .$row['optiond']; "<br/>";
}
$c=$a-1;
$b=$a+1;
echo "<input type='hidden' value='$c' name='a'>";
echo "<input type='submit' name='previous' value='previous'> ";
echo "<input type='hidden' value='$b' name='a'>";
echo "<input type='submit' name='next' value='next'> ";
echo "<input type='reset' name='reset' value='Reset'>";
echo "</form>";
?>