[英]Validate correct answer and add marks in PHP quiz
我正在開發一個簡單的測驗Web應用程序,我想驗證提交按鈕上的每個問題,以顯示正確的問題並為正確的問題添加標記。
我已經像這樣創建了我的第一個問題頁面
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cric Quiz </title>
<link href="<?php echo base_url(); ?>assets/style.CSS" rel="stylesheet" type="text/css"/>
</head>
<body>
<div>
<h1>Cric Quiz</h1>
</div>
<div id='quesNo'>
<center>Question 01</center>
</div>
<div id='questions'>
<center>When did Australia win their first ever world cup?</center>
</div>
<div id='answers'>
<input type="radio" name="year" value="1992">1992<br>
<input type="radio" name="year" value="1996">1996<br>
<input type="radio" name="year" value="2000">2000<br>
<input type="radio" name="year" value="2012">2012
</div>
<center><a href="<?=base_url().'index.php/Questions/question_2';?>" class="button1">Next</a></center>
</body>
</html>
我的控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Questions extends CI_Controller {
public function question_1()
{
$this->load->view('quiz_one');
}
public function question_2()
{
$this->load->view('quiz_two');
}
}
如何在控制器中驗證我的答案
PS:我正在使用codeigniter
您的方法是錯誤的。 只需具有一個功能,然后將問題ID傳遞給該功能即可。 如果明天有1000個問題,會創建盡可能多的函數嗎?
首先將正確答案存儲在數據庫中。
接下來,您的html應該具有表單,並提交帶有發布數據的表單
在表單發布中發布問題ID
將此代碼添加到控制器中,
// run query to fetch data from database based on the question in
if($this->input->post("year") == "value from database"){
} else {
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.