我已经创建了一个测验程序,我无法生成正确的结果,即使我选择了错误的单选按钮我得到了正确的答案和所有填充我的空白显示正确的答案,即使我留空.please帮我解决这个问题。我需要为我的项目完成这项工作,我需要快速完成,
HTML code:
<?php
//include auth.php file on all secure pages
?>
<html>
<head>
<title>online examination system</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="style2.css">
<meta charset="UTF-8">
<script language="javascript" type="text/javascript" src="libraries/p5.js"></script>
<script language="javascript" src="libraries/p5.dom.js"></script>
<script language="javascript" src="libraries/p5.sound.js"></script>
<script language="javascript" type="text/javascript" src="sketch.js"> </script>
</head>
<body>
<div class=header>
<img class="img-style" src="Online-Examination-System-Banner.jpeg" width="1166px" height="250px">
</div>
<div class="top">
<ul id="navigation">
<li><a href="index.php">HOME</a></li>
<li><a href="aboutus.php">ABOUT US</a></li>
<li><a href="examination.php">EXAMINATION</a></li>
<li><a href="login.php">LOGIN</a></li>
<li><a href="logout.php">LOGOUT</a></li>
</ul>
</div>
<p style="font-size:40;color:white;font-weight:bolder;">Welcome !</p>
<center><p id="timer" style="color:white;font-family:courier;font-size:28px;">______</p></center>
<form action="result.php" method="post" >
<div style="margin-top:10px;margin-right:85px;margin-left:100px;margin- bottom:20px;background:rgba(0,0,0,0.5)">
<p style="color:white;font-family:courier;font-size:18px">1. Which of the following correctly declares an array?</p> <br>
<input class="exam-btn" type="radio" name="q1" id="q1-a" value="A" >
<label for="q1-a" style="color:white;font-family:courier;font-size:18px">int array[10];</label>
<input class="exam-btn" type="radio" name="q1" id="q1-b" value="B">
<label style="color:white;font-family:courier;font-size:18px">int array;</label>
<input class="exam-btn" type="radio" name="q1" id="q1-c" value="C">
<label style="color:white;font-family:courier;font-size:18px">array{10};</label>
<input class="exam-btn" type="radio" name="q1" id="q1-d" value="D">
<label style="color:white;font-family:courier;font-size:18px">array array[10];</label>
<br><br><br><br>
<p style="color:white;font-family:courier;font-size:18px">2. What is the index number of the last element of an array with 9 elements?</p> <br>
<input class="exam-btn" type="radio" name="q2" id="q2-a" value="A">
<label style="color:white;font-family:courier;font-size:18px">9</label>
<input class="exam-btn" type="radio" name="q2" id="q2-b" value="B" >
<label style="color:white;font-family:courier;font-size:18px">8</label>
<input class="exam-btn" type="radio" name="q2" id="q2-c" value="C">
<label style="color:white;font-family:courier;font-size:18px">0</label>
<input class="exam-btn" type="radio" name="q2" id="q2-d" value="D">
<label style="color:white;font-family:courier;font-size:18px">programmer defined</label>
<br><br><br><br>
<p style="color:white;font-family:courier;font-size:18px">3. Which of the following accesses the seventh element stored in array?</p> <br>
<input class="exam-btn" type="radio" name="q3" id="q3-a" value="A" >
<label style="color:white;font-family:courier;font-size:18px">array[6];</label>
<input class="exam-btn" type="radio" name="q3" id="q3-b" value="B" >
<label style="color:white;font-family:courier;font-size:18px">array[7];</label>
<input class="exam-btn" type="radio" name="q3" id="q3-c" value="C" >
<label style="color:white;font-family:courier;font-size:18px">array(7);</label>
<input class="exam-btn" type="radio" name="q3" id="q3-d" value="D" >
<label style="color:white;font-family:courier;font-size:18px">array;</label>
<br><br><br><br>
<p style="color:white;font-family:courier;font-size:18px">4. Which of the following gives the memory address of the first element in array?</p> <br>
<input class="exam-btn" type="radio" name="q4" id="q4-a" value="A" >
<label style="color:white;font-family:courier;font-size:18px">array[0];</label>
<input class="exam-btn" type="radio" name="q4" id="q4-b" value="B" >
<label style="color:white;font-family:courier;font-size:18px">array[1];</label>
<input class="exam-btn" type="radio" name="q4" id="q4-c" value="C" >
<label style="color:white;font-family:courier;font-size:18px">array[2];</label>
<input class="exam-btn" type="radio" name="q4" id="q4-d" value="D" >
<label style="color:white;font-family:courier;font-size:18px">none</label>
<br><br><br><br>
<p style="color:white;font-family:courier;font-size:18px">5. What will be the output of this program?</p> <br>
<pre style="color:white;font-family:courier;font-size:18px">
#include <stdio.h>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main()
{
for (temp = 0; temp < 5; temp++)
{
result += array1[temp];
}
for (temp = 0; temp < 4; temp++)
{
result += array2[temp];
}
cout << result;
return 0;
}
</pre>
</pre>
<input class="exam-btn" type="radio" name="q5" id="q5-a" value="A" >
<label style="color:white;font-family:courier;font-size:18px">6553</label>
<input class="exam-btn" type="radio" name="q5" id="q5-b" value="B" >
<label style="color:white;font-family:courier;font-size:18px">6533</label>
<input class="exam-btn" type="radio" name="q5" id="q5-c" value="C" >
<label style="color:white;font-family:courier;font-size:18px">6522</label>
<input class="exam-btn" type="radio" name="q5" id="q5-d" value="D" >
<label style="color:white;font-family:courier;font-size:18px">12200</label>
<br><br><br><br>
<! 1. token 2. sensitive 3. identifiers
4. octal 5. \0n -->
<p style="color:white;font-family:courier;font-size:18px">6.The smallest individual unit in a program is known as a …………………… </p> <br>
<p style="color:white;font-family:courier;font-size:18px">ans</p><input class="exam-btn" type="text" name="q6" >
<br><br><br><br>
<p style="color:white;font-family:courier;font-size:18px">7.C++ Language is case …………………. </p> <br>
<p style="color:white;font-family:courier;font-size:18px">ans</p><input class="exam-btn" type="text" name="q7" >
<br><br><br><br>
<p style="color:white;font-family:courier;font-size:18px">8.An ………………… is a long sequence of letters and digits. </p> <br>
<p style="color:white;font-family:courier;font-size:18px">ans</p><input class="exam-btn" type="text" name="q8" >
<br><br><br><br>
<p style="color:white;font-family:courier;font-size:18px">9.A sequence of digits beginning with zero is considered to be …………….number. </p> <br>
<p style="color:white;font-family:courier;font-size:18px">ans</p><input class="exam-btn" type="text" name="q9" >
<br><br><br><br>
<p style="color:white;font-family:courier;font-size:18px">10.………………. escape sequence represents the given number in octal form. </p> <br>
<p style="color:white;font-family:courier;font-size:18px">ans</p>
<input class="exam-btn" type="text" name="q10" >
<br><br><br><br>
<input style="border:none;outline:none;background:cyan;height:50px;width:180px;color:white;font-family:courier;font-weight:bolder;font-size:18px;border-radius:60px;cursor:pointer" type="submit" value="Submit quiz">
</div>
<div style="font-size:18px;color:white;font-weight:bolder;">
<?php
$answer1;
$answer2;
$answer3;
$answer4;
$answer5;
$answer6;
$answer7;
$answer8;
$answer9;
$answer10;
$answer1 = isset($_POST['q1']) ;
$answer2 = isset($_POST['q2']) ;
$answer3 = isset($_POST['q3']) ;
$answer4 = isset($_POST['q4']) ;
$answer5 = isset($_POST['q5']) ;
$answer6 = isset($_POST['q6']) ;
$answer7 = isset($_POST['q7']) ;
$answer8 = isset($_POST['q8']) ;
$answer9 = isset($_POST['q9']) ;
$answer10 = isset($_POST['q10']) ;
$totalcorrect;
$totalcorrect = 0;
if($answer1 == "A") {$totalcorrect++;}
if($answer2 == "B") {$totalcorrect++;}
if($answer3 == "A") {$totalcorrect++;}
if($answer4 == "D") {$totalcorrect++;}
if($answer5 == "B") {$totalcorrect++;}
if($answer6 == "token") {$totalcorrect++;}
if($answer7 == "sensitive") {$totalcorrect++;}
if($answer8 == "identifier") {$totalcorrect++;}
if($answer9 == "octal") {$totalcorrect++;}
if($answer10 == "\0n") {$totalcorrect++;}
?>
</div>
</form>
</body>
</html>
php code:
<?php
//include auth.php file on all secure pages
?>
<html>
<head>
<title>online examination system</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="style2.css">
<meta charset="UTF-8">
<script language="javascript" type="text/javascript" src="libraries/p5.js"></script>
<script language="javascript" src="libraries/p5.dom.js"></script>
<script language="javascript" src="libraries/p5.sound.js"></script>
<script language="javascript" type="text/javascript" src="sketch.js"> </script>
</head>
<body>
<div class=header>
<img class="img-style" src="Online-Examination-System-Banner.jpeg" width="1166px" height="250px">
</div>
<div class="top">
<ul id="navigation">
<li><a href="index.php">HOME</a></li>
<li><a href="aboutus.php">ABOUT US</a></li>
<li><a href="examination.php">EXAMINATION</a></li>
<li><a href="login.php">LOGIN</a></li>
<li><a href="logout.php">LOGOUT</a></li>
</ul>
</div>
<p style="font-size:40;color:white;font-weight:bolder;">Welcome !</p>
<br><br><br><br><center>
<div style="font-size:34px;color:cyan;font-weight:bolder;background:rgba(0,0,0,0.4)">
<?php
$answer1 = isset($_POST['q1']) ;
$answer2 = isset($_POST['q2']) ;
$answer3 = isset($_POST['q3']) ;
$answer4 = isset($_POST['q4']) ;
$answer5 = isset($_POST['q5']) ;
$answer6 = isset($_POST['q6']) ;
$answer7 = isset($_POST['q7']) ;
$answer8 = isset($_POST['q8']) ;
$answer9 = isset($_POST['q9']) ;
$answer10 = isset($_POST['q10']) ;
$totalcorrect = 0;
if($answer1 == "A") {$totalcorrect++;}
if($answer2 == "B") {$totalcorrect++;}
if($answer3 == "A") {$totalcorrect++;}
if($answer4 == "D") {$totalcorrect++;}
if($answer5 == "B") {$totalcorrect++;}
if($answer6 == "token") {$totalcorrect++;}
if($answer7 == "sensitive") {$totalcorrect++;}
if($answer8 == "identifier") {$totalcorrect++;}
if($answer9 == "octal") {$totalcorrect++;}
if($answer10 == "\0n") {$totalcorrect++;}
echo "TOTAL CORRECT ANSWERS ARE ".$totalcorrect." OUT OF 10 QUESTIONS";
?>
<br><br><br>
<p style="font-size:28;color:white;font-weight:bolder;font-family:courier">Fill up the following data</p>
<form action="thanks.php" method="post">
<center><br><br>
<label style="color:white;font-weight:bolder;font-family:courier">How would you like to rate the test</label><br><br>
<table cellspacing="50">
<tr>
<td><img src="star.png" width="80px" height="80px"><br>& nbsp; <input type="radio" name="rate"></td>
<td><img src="star.png" width="80px" height="80px"><br> <input type="radio" name="rate"></td>
<td><img src="star.png" width="80px" height="80px"><br> <input type="radio" name="rate"></td>
<td><img src="star.png" width="80px" height="80px"><br> <input type="radio" name="rate"></td>
<td><img src="star.png" width="80px" height="80px"><br> <input type="radio" name="rate"></td>
</tr>
</table><br><br>
<label style="color:white;font-weight:bolder;font-family:courier">Your experience during the test:</label><br>
<textarea cols="50" rows="10">
</textarea><br><br>
<input style="border:none;outline:none;background:cyan;height:50px;width:180px;color:white;font-family:courier;font-weight:bolder;font-size:18px;border-radius:60px;cursor:pointer" type="submit" name="sub-feedback" value="SUBMIT FEEDBACK" ><br><br><br>
</center></form>
<br><br><br>
</div>
</center>
</body>
</html>
答案 0 :(得分:1)
$answer1 = isset($_POST['q1']) ;
Isset检查变量是否设置(null)。返回true或false。 因此$ answer1不等于$ _POST ['q1'],而是等于true。
如果你想检查它是否已设置并给它一个值,你必须检查它是否已设置然后分配值,如果没有设置,我只会指定false:
$answer1 = (isset($_POST['q1'])) ? $_POST['q1'] : false;
然后,检查:
if($answer1 == "A") // if TRUE == "A"
虽然$ answer = True,但PHP也会将“A”字样改为true。 您需要了解PHP类型杂耍:http://php.net/manual/en/language.types.type-juggling.php
一旦你纠正了如上所述的$ answer1 = isset([...]),你应该严格按照你的字符串检查答案,以确保:
if($answer1 === "A"){}
注意3“=”的标志。
同样在你的第10个问题验证中,你需要逃避反斜杠或使用单引号引起你的回答:
if($answer10 === "\\0n") {$totalcorrect++;}
OR
if($answer10 === '\0n') {$totalcorrect++;}
很好地阅读了php中的双引号和单引号:What is the difference between single-quoted and double-quoted strings in PHP?