我并不是真的想做多少,我试图检查变量是否匹配表中的值,如果是,它会增加存储在$ mark中的值。
即。 2/5正确的测验给出$ mark值40。
目前,它的作用是输出,即使检查“应该”失败,它的值为100。
如果有人可能告诉我我是如何搞砸的话,我会很感激。 :d
我试图计算的PHP页面。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include ("dbfunctions.php");
//print first part of html
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Results</title>
</head>
<body>
<h1>Results</h1>
<?php
//retrieve username and password
$username = "username";
$password = "password";
//connect to database
$dbConn = dbConnect("$username", "$password") ;
dbSelect($dbConn, "$username");
//retrieve pet and number of tins from the form
$question1 = $_POST['question1'];
$question2 = $_POST['question2'];
$question3 = $_POST['question3'];
$question4 = $_POST['question4'];
$question5 = $_POST['question5'];
$mark=0;
$query = "SELECT * FROM footballdb_prototype";
$result = runQuery($dbConn, $query);
if($numrows = mysqli_num_rows($result)){
if ($numrows == 0)
{
print "<p>There was nothing in the table</p>";
print "</body>";
print "</html>";
exit();
}
echo("some results");
//check to see if answer matches database
while($row = mysqli_fetch_assoc($result)) {
if ("SELECT * FROM footballdb_prototype WHERE '$question1' = question1"){
$mark += 20;
}
if ("SELECT * FROM footballdb_prototype WHERE '$question2' == question2"){
$mark += 20;
}
if ("SELECT * FROM footballdb_prototype WHERE '$question3' == question3"){
$mark += 20;
}
if ("SELECT * FROM footballdb_prototype WHERE '$question4' == question4"){
$mark += 20;
}
if ("SELECT * FROM footballdb_prototype WHERE '$question5' == question5"){
$mark += 20;
}
}
}
else {
echo "we fucked";
}
echo "<p>You scored $mark %";
mysqli_close($dbConn);
?>
</body>
</html>
变量值来自的HTML页面。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Think you know?</title>
<meta charset="utf-8" />
<link rel = "stylesheet" href = "Prototype.css" type = "text/css" />
<meta name = "viewport" content = "width=device-width, initial-scale = 1.0">
</head>
<body class="body">
<header class = "mainHeader">
<img src = banner.png>
<nav><ul>
<li><a href = "homepage.html">Home </a></li>
<li class = "active"><a href = "Quiz.php">Quiz</a></li>
<li> <a href = "Aboutus.html">Profile</a></li>
<li><a href = "Login.php">Login</a></li>
<li><a href = "Logout.php">Logout</a></li>
</ul></nav>
</header>
<div class="mainContent">
<div class = "content">
<head>
<title>Football Quiz</title>
</head>
<body>
<form method=POST action="football_quiz_prototype.php">
<h1>Think you know your football?<h1>
<br>
<h2>What's a hat-trick?</h2>
<br>
<input type="radio" name="question1" value="1 Goal" checked> 1 Goal<t>
<input type="radio" name="question1" value="3 Own Goals"> 3 Own Goals<br>
<input type="radio" name="question1" value="2 Goals"> 2 Goals<t>
<input type="radio" name="question1" value="3 Goals"> 3 Goals<br>
<br>
<br>
<h2>Who won the 2007 UEFA Champions League?</h2>
<br>
<input type="radio" name="question2" value="AC Milan" checked> AC Milan<t>
<input type="radio" name="question2" value="Barcelona"> Barcalona<br>
<input type="radio" name="question2" value="Real Madrid"> Real Madrid<t>
<input type="radio" name="question2" value="Liverpool"> Liverpool<br>
<br>
<br>
<h2>What is constituted "off-side"?</h2>
<br>
<input type="radio" name="question3" value="Standing behind the midfielders" checked> Standing behind the midfielders<t>
<input type="radio" name="question3" value="Standing behind all of the defenders during open-play"> Standing behind all of the defenders during open-play<br>
<input type="radio" name="question3" value="Standing outside the pitch"> Standing outside the pitch<t>
<input type="radio" name="question3" value="Standing behind all of the defenders during a throw-in"> Standing behind all of the defenders during a throw-in<br>
<br>
<br>
<h2>What is the "Old Firm"?</h2>
<br>
<input type="radio" name="question4" value="Chelsea vs Arsenal" checked> Chelsea vs Arsenal<t>
<input type="radio" name="question4" value="Celtic vs Barcelona"> Celtic vs Barcelona<br>
<input type="radio" name="question4" value="Rangers vs Motherwell"> Rangers vs Motherwell<t>
<input type="radio" name="question4" value="Celtic vs Rangers"> Celtic vs Rangers<br>
<br>
<br>
<h2>What was the result of the 2014 FIFA World Cup Semi-Final, Germany vs Brazil?</h2>
<br>
<input type="radio" name="question5" value="Germany: 5 - Brazil: 0" checked> Germany: 5 - Brazil: 0<t>
<input type="radio" name="question5" value="Brazil: 7 - Germany: 1"> Brazil: 7 - Germany: 1<br>
<input type="radio" name="question5" value="Germany: 7 - Brazil: 1"> Germany: 7 - Brazil: 1<t>
<input type="radio" name="question5" value="Germany: 2 - Brazil: 5"> Germany: 2 - Brazil: 5<br>
<br>
<br>
<input type="submit">
<input type="reset">
</form>
</content>
</div>
<footer class ="mainFooter">
<p>Copyright © 2017</p>
</footer>
</body>
</html>