duhmartinsdmly Postado Outubro 19, 2016 Denunciar Share Postado Outubro 19, 2016 [INDEX.PHP] <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>PHP Quiz</title> <link rel="stylesheet" type="text/css" href="css/style.css" /> </head> <body> <div id="page-wrap"> <h1>Quiz</h1> <form action="processa.php" method="post" id="quiz"> <ol> <li> <h3>Pergunta 1</h3> <div> <input type="radio" name="question-1-answers" id="question-1-answers-A" value="A" /> <label for="question-1-answers-A">A) OpçãoA </label> </div> <div> <input type="radio" name="question-1-answers" id="question-1-answers-B" value="B" /> <label for="question-1-answers-B">B) OpçãoB</label> </div> <div> <input type="radio" name="question-1-answers" id="question-1-answers-C" value="C" /> <label for="question-1-answers-C">C) OpçãoC</label> </div> <div> <input type="radio" name="question-1-answers" id="question-1-answers-D" value="D" /> <label for="question-1-answers-D">D) OpçãoD</label> </div> </li> <li> <h3>Pergunta 2</h3> <div> <input type="radio" name="question-2-answers" id="question-2-answers-A" value="A" /> <label for="question-2-answers-A">A) OpçãoA</label> </div> <div> <input type="radio" name="question-2-answers" id="question-2-answers-B" value="B" /> <label for="question-2-answers-B">B) OpçãoB</label> </div> <div> <input type="radio" name="question-2-answers" id="question-2-answers-C" value="C" /> <label for="question-2-answers-C">C) OpçãoC</label> </div> <div> <input type="radio" name="question-2-answers" id="question-2-answers-D" value="D" /> <label for="question-2-answers-D">D) OpçãoD</label> </div> </li> </ol> <input type="submit" value="Submit Quiz" /> <input type="reset" value="Limpar" /> </form> </div> </body> </html> [PROCESSA.PHP] <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>PHP Quiz</title> <link rel="stylesheet" type="text/css" href="css/style.css" /> </head> <body> <div id="page-wrap"> <h1>Quiz</h1> <?php $answer1 = $_POST['question-1-answers']; $answer2 = $_POST['question-2-answers']; $answer3 = $_POST['question-3-answers']; $totalCorrect = 0; if ($answer1 == "B") { $totalCorrect++; } if ($answer2 == "A") { $totalCorrect++; } if ($answer3) { $totalCorrect++; } echo "<div id='results'>Acerto $totalCorrect de 2 corretas</div>"; ?> </div> </body> </html> Citar Link para o comentário Compartilhar em outros sites More sharing options...
0 joehdesigner Postado Outubro 24, 2016 Denunciar Share Postado Outubro 24, 2016 Duvidas sobre PHP? Entre no chat Discord :) https://discord.gg/23FHWUW Citar Link para o comentário Compartilhar em outros sites More sharing options...
Pergunta
duhmartinsdmly
[INDEX.PHP]
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PHP Quiz</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz</h1>
<form action="processa.php" method="post" id="quiz">
<ol>
<li>
<h3>Pergunta 1</h3>
<div>
<input type="radio" name="question-1-answers" id="question-1-answers-A" value="A" />
<label for="question-1-answers-A">A) OpçãoA </label>
</div>
<div>
<input type="radio" name="question-1-answers" id="question-1-answers-B" value="B" />
<label for="question-1-answers-B">B) OpçãoB</label>
</div>
<div>
<input type="radio" name="question-1-answers" id="question-1-answers-C" value="C" />
<label for="question-1-answers-C">C) OpçãoC</label>
</div>
<div>
<input type="radio" name="question-1-answers" id="question-1-answers-D" value="D" />
<label for="question-1-answers-D">D) OpçãoD</label>
</div>
</li>
<li>
<h3>Pergunta 2</h3>
<div>
<input type="radio" name="question-2-answers" id="question-2-answers-A" value="A" />
<label for="question-2-answers-A">A) OpçãoA</label>
</div>
<div>
<input type="radio" name="question-2-answers" id="question-2-answers-B" value="B" />
<label for="question-2-answers-B">B) OpçãoB</label>
</div>
<div>
<input type="radio" name="question-2-answers" id="question-2-answers-C" value="C" />
<label for="question-2-answers-C">C) OpçãoC</label>
</div>
<div>
<input type="radio" name="question-2-answers" id="question-2-answers-D" value="D" />
<label for="question-2-answers-D">D) OpçãoD</label>
</div>
</li>
</ol>
<input type="submit" value="Submit Quiz" />
<input type="reset" value="Limpar" />
</form>
</div>
</body>
</html>
[PROCESSA.PHP]
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PHP Quiz</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz</h1>
<?php
$answer1 = $_POST['question-1-answers'];
$answer2 = $_POST['question-2-answers'];
$answer3 = $_POST['question-3-answers'];
$totalCorrect = 0;
if ($answer1 == "B") { $totalCorrect++; }
if ($answer2 == "A") { $totalCorrect++; }
if ($answer3) { $totalCorrect++; }
echo "<div id='results'>Acerto $totalCorrect de 2 corretas</div>";
?>
</div>
</body>
</html>
Link para o comentário
Compartilhar em outros sites
1 resposta a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.