0
我想創建一個輪詢系統,其中用戶可以選擇單選按鈕,選擇將在數據庫中遞增遞增共享價值數據庫
insert_view.php - 簡單形式插入,用於選擇所需的字段
<html>
<body>
<?php echo form_open('insert_ctrl'); ?>
<h1>Insert Data Into Database Using CodeIgniter</h1><hr/>
<?php if (isset($message)) { ?>
<CENTER><h3 style="color:green;">Data inserted successfully</h3></CENTER> <br>
<?php } ?>
<?php echo "which language do you prefer..?";?><br/>
<?php echo form_radio(array('id' => 'rad1', 'name' => 'rad1','value'=>0)); ?>
<?php echo form_label('JAVA'); ?> <?php echo form_error('rad1'); ?><br />
<?php echo form_radio(array('id' => 'rad2', 'name' => 'rad2','value'=>0)); ?>
<?php echo form_label('PHP'); ?> <?php echo form_error('rad2'); ?><br />
<?php echo form_radio(array('id' => 'rad3', 'name' => 'rad3','value'=>0)); ?>
<?php echo form_label('C\C++'); ?> <?php echo form_error('rad3'); ?><br />
<?php echo form_radio(array('id' => 'rad4', 'name' => 'rad4','value'=>0)); ?>
<?php echo form_label('DOTNET'); ?> <?php echo form_error('rad4'); ?><br />
<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit')); ?>
</body>
</html>
insert_ctrl.php - 用於通過控制器的幫助從視圖發送請求到模型。
<?php
class insert_ctrl extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->model('insert_model');
}
function index() {
$data = array(
'Option1' => $this->input->post('rad1'), //for selecting the required option
'Option2' => $this->input->post('rad2'), //for selecting the required option
'Option3' => $this->input->post('rad3'), //for selecting the required option
'Option4' => $this->input->post('rad4')
);
$vote = $this->input->post('Submit');
if($vote=="Option1"){
$value=$value+1;
}
elseif($vote=="Option2"){
$value=$value+1;
}
elseif($vote=="Option3"){
$value=$value+1;
}
elseif($vote=="Option4"){
$value=$value+1;
}
//Setting values for tabel columns
//Transfering data to Model
$this->insert_model->form_insert($data);
//$data['message'] = 'Data Inserted Successfully';
//Loading View
$this->load->view('insert_view', $data);
}
}
?>
insert_model.php
<?php
class insert_model extends CI_Model{
function __construct() {
parent::__construct();
}
function form_insert($data){
// Inserting in Table(students) of Database(college)
$this->db->insert('students', $data);
}
}
?>
這是非常好的,我們知道你想要什麼..你想這真的很糟糕..現在..有什麼問題?請不要重複超過10次..謝謝 –
真正的問題是什麼? – ciruvan
很棒..我也想要一輛寶馬..但是不幸的是,我不能在這裏寫下爲什麼我不能擁有它.. –