我似乎无法弄清楚如何从表单中获取结果。我在一个名为“written.php”的文件中使用php编写了表单:
<!DOCTYPE html>
<html>
<head>
<title>PHP Written Test</title>
</head>
<body>
<?php
$questions=array(
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is malware?",
"A program a user can use to create and manage spreadsheets",
"The software that controls everything inside the computer. It controls the hardware and software the user works with",
"Programs that intend to damage a users data and system files or allow an outside attacker to gain access to the computer and steal data",
"A web browser",
"Programs that intend to damage a users data and system files or allow an outside attacker to gain access to the computer and steal data"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What program controls items such as the start menu, windows, and the taskbar?",
"Spybot Search and Destroy",
"Internet Explorer",
"Word",
"Explorer",
"Explorer"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is a folder?",
"A location that stores saved files and programs",
"A paper document inside a file cabinet",
"The Start button",
"A type of file",
"A location that stores saved files and programs"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is an input device?",
"Keyboard",
"Monitor",
"Printer",
"Motherboard",
"Keyboard"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is the brain of the computer?",
"GPU",
"CPU",
"Motherboard",
"Monitor",
"CPU"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is an operating system?",
"A word processing program that allows the user to edit text and format it",
"Motherboard",
"An important part of systems files. It manages the interaction between the user, application programs, and hardware",
"A program that infects a computer, copies itself many times using up system resources, and spreads the infection to other computers",
"An important part of systems files. It manages the interaction between the user, application programs, and hardware"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What are the small pictures on the desktop called?",
"Icons",
"Folders",
"Recycle Bin",
"File Type",
"Icons"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is the bar at the bottom of the screen called?",
"Shortcut",
"System Tray",
"Program",
"Taskbar",
"Taskbar"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"Where can you find a list of all the storage devices connected to the computer?",
"Control Panel",
"Computer",
"Documents",
"Desktop",
"Computer"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is Task Manager?",
"A program that manages your tasks",
"A program that lets your organize data into databases",
"An operating system",
"A utility program used for managing processes and programs running on the computer",
"A utility program used for managing processes and programs running on the computer"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is the default web browser for Windows?",
"Firefox",
"Safari",
"Google Chrome",
"Internet Explorer",
"Internet Explorer"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"Where do you type links to take you to different web sites?",
"Menu Bar",
"Address Bar",
"Search Bar",
"Favorites Bar",
"Address Bar"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is a search engine?",
"Software enabling the user to organize emails",
"A program that allows a user to store, manage, manipulate, and secure data then make queries",
"A tool used to lookup information on the internet",
"The program that runs the internet browser",
"A tool used to lookup information on the internet"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"The first page displayed after starting the web browser is called what?",
"The home page",
"The search engine",
"Web Page 1",
"google.com",
"The home page"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"To refresh a web page you may?",
"Press the F13 key",
"Press the white \"-\" at the top of the window",
"Press the red \"X\" key at the top of the page",
"Click the refresh button",
"Click the refresh button"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"Email is?",
"Software programs that can compose, send, and receive email messages",
"The default folder that stores deleted messages",
"A service that allows users to send messages and/or documents to each other over an internet network",
"hotmail.com",
"A service that allows users to send messages and/or documents to each other over an internet network"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"Phishing is?",
"Impersonating someone with a similar email address and trying to obtain sensitive information from the recipient",
"Creating a carbon copy of your email",
"Updating software",
"Composing a new email message and sending it",
"Impersonating someone with a similar email address and trying to obtain sensitive information from the recipient"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"The three parts of an email address in order are?",
"User ID, @ symbol, host name",
"GB, MB, KB",
"IP, DNS, ISP",
"CPU, Motherboard, Video Cards",
"User ID, @ symbol, host name"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is a carbon copy?",
"A copy of the email sent to the recipient emailed to you",
"A physical copy of the email",
"Writing the email down on paper with pencil",
"Copying the email onto the desktop to view later",
"A copy of the email sent to the recipient emailed to you"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"Where do you type the recipient's name in a new email?",
"The message itself",
"The \"From\" line",
"The Search Bar",
"The \"To\" line",
"The \"To\" line"
),
);
$numbers = array(
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
);
$x = 1;
ob_start();
echo "<div style=\"margin-left:25%; \">"
."<form name=\"post\" action=\"score.php\" method=\"get\">";
while ($x <= 20)
{
$num=array_rand($numbers);
echo $numbers[$num]."<br>";
echo "<label>" . $x . ".) " . $questions[$numbers[$num]][0] . "</label>"
. "<p style=\"text-align:left;\">"
. "<input type=\"radio\" name=\"question" . $x . "\" value=\"". $questions[$numbers[$num]][1] . " \" required >" . $questions[$numbers[$num]][1] . "<br>"
. "<input type=\"radio\" name=\"question" . $x . "\" value=\"". $questions[$numbers[$num]][2] . " \">" . $questions[$numbers[$num]][2] . "<br>"
. "<input type=\"radio\" name=\"question" . $x . "\" value=\"". $questions[$numbers[$num]][3] . " \">" . $questions[$numbers[$num]][3] . "<br>"
. "<input type=\"radio\" name=\"question" . $x . "\" value=\"". $questions[$numbers[$num]][4] . " \">" . $questions[$numbers[$num]][4] . "<br>"
. "</p>";
array_splice($numbers,$num,1);
$x++;
}
?>
<br><input style="margin-left:25%;" type="submit" name="submit" value="Finish Test">
</form>
</div>
</body>
</html>
我正在尝试将帖子结果放在一个名为“score.php”的不同php文件中,但没有任何反应。显然我做错了,有人可以告诉我如何正确地做到这一点吗?我想得到帖子的结果,这样我就可以看到他们选择了哪个答案,然后将其与数组中存储的正确答案进行比较,这样我就可以给它们评分/如果答案不正确就给他们正确答案。
<!DOCTYPE html>
<html>
<head>
<title>PHP Written Test</title>
</head>
<body>
<?php include 'written.php';
//ob_end_clean();
echo "Testing if it works?";
if(isset($_POST['submit']))
{
$uAnswer = $_POST["question1"];
echo $uAnswer;
}
?>
</body>
</html>
答案 0 :(得分:2)
您正在使用get
向score.php
发送数据,并检查您是否收到了post
数据。改变两者中的任何一个。
"<form name=\"post\" action=\"score.php\" method=\"POST\">";