My problem is as follows, I have a page called index.php with the following code
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="POST" action="questions.php">
<input type="submit" name="x" value="historia" />
<input type="submit" name="x" value="tecnologia" />
<input type="submit" name="x" value="matematica" />
<input type="submit" name="x" value="brasil" />
</form>
</body>
</html>
and I have the questions.php page with the following:
<?php
include_once './config.php';
$theme = $_POST['x'];
$auxteste = "SELECT * FROM db_infos WHERE assunto = '$theme' order by
rand()";
$teste = mysqli_query($conexao, $auxteste);
while ($infos = mysqli_fetch_assoc($teste)) {
?>
<html>
<body>
<form action="questions.php" method="POST">
<b><?php echo $infos['questao'] ?></b><br>
<input type="radio" name="alt" value=<?php echo $infos['alt1'] ?>><?php echo $infos['alt1'] ?><br>
<input type="radio" name="alt" value=<?php echo $infos['alt2'] ?>><?php echo $infos['alt2'] ?><br>
<input type="radio" name="alt" value=<?php echo $infos['alt3'] ?>><?php echo $infos['alt3'] ?><br>
<input type="radio" name="alt" value=<?php echo $infos['alt4'] ?>><?php echo $infos['alt4'] ?><br>
<input type="radio" name="alt" value=<?php echo $infos['alt5'] ?>><?php echo $infos['alt5'] ?><br>
<input type="radio" name="alt" value=<?php echo $infos['resposta'] ?>><?php echo $infos['resposta'] ?><br> <!-- RESPOSTA DO BANCO PARA A PERGUNTA -->
<input type="submit" name="enviar" value="Responder" />
</form>
</body>
</html>
<?php
} //FECHANDO WHILE
?>
<?php
if (isset($_POST['enviar']))
{
if ($_POST['alt'] == $infos['resposta'])
{
header("refresh:0; index.php");
exit;
}else
{
header("refresh: 3; login.php");
}
}else
{
echo "Escolha uma das opções!";
}
?>
And I have my bank with 9 columns, which include:
- ID, subject, question, alt1, alt2, alt3, alt4, alt5, response (that latter is equal to one of alt)
What I need help with is that when the person responds on the page questions.php
, regardless of whether it is right or wrong, it directs you to the login.php
screen, but before that it gives this error:
Notice: Undefined index: x in C:\xampp\htdocs\quizProject\questions.php on line 11
-
How do I redirect to the login screen if the person fails on the screen
questions.php
did she hit the question? -
How do I, if the person answers the question, on the same page (
questions.php
or another), another question appears, on the same topic, but different from the previous question that the person this one is never repeated again?)
If you have to do something ajax , could someone give me a light seeing that I never mess with the same?