我试图将3个不同表和1个varchar中的3个id发送到一个名为'session'的表中,它将在其中保存id和这个varchar,我的问题是,每次我单击提交时,它都不会向表中输入任何内容,并且没有错误显示。
视图
<link href='<?php echo site_url('assets/recursos/dashboard.css');?>' rel="stylesheet">
<div class="container">
<?php echo form_open('admin/inserirsessao'); ?>
<?php if (isset($message)) { ?>
<CENTER><h3 style="color:green;">Data inserted successfully</h3></CENTER><br>
<?php } ?>
<div class="col-xs-12">
<div class="form-group">
<label for="sel1">Filme</label>
<select name='filmes' class="form-control" id="filmes">
<?php
$id = $this->uri->segment(4);
$this->db->where('filme_id', $id);
$lista = $this->db->get('filme');
foreach($lista->result() as $row) {
?>
<option value="<?php echo $row->filme_id;?>"> <?php echo $row->Nome; ?></option>
<?php
}
?>
</select>
</div>
</div>
<h2 style="color:white; font-size:25px;">Adiciona um Filme<h2>
<div class="col-xs-12 ">
<div class="form-group">
<label for="sel1">Seleciona as Salas</label>
<select name='salas' class="form-control" id="salas">
<?php
$lista = $this->db->get('sala');
foreach($lista->result() as $row) {
?>
<option value="<?php echo $row->sala_id;?>" > <?php echo $row->description; ?></option>
<?php
}
?>
</select>
</div>
<div class="col-xs-12">
<div class="form-group">
<label for="sel1">Seleciona tipo de filme</label>
<select name="tipofilme" class="form-control" id="tipofilme">
<?php
$lista = $this->db->get('tipo_filme');
foreach($lista->result() as $row) {
?>
<option value="<?php echo $row->tipo_filme_id;?>"><?php echo $row->tipo_filme; ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="col-xs-12">
<p style="color:white" class="text-center">Insere Hora da Sessão</p>
<div class="separator">
<?php echo form_label('Hora:'); ?> <?php echo form_error('hora'); ?>
<?php echo form_input(array('id' => 'hora', 'name' => 'hora')); ?><br />
</div>
</div>
</ul>
</li>
<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit')); ?> <br/>
<?php echo form_close(); ?><br/>
</div>
</div>
</div>
控制器
public function index()
{
$this->render('admin/inseresessao');
}
public function sessao()
{
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
//Validating Name Field
$this->form_validation->set_rules('hora', 'Hora', 'required');
if ($this->form_validation->run() == FALSE) {
$this->render('admin/inserirsessao');
} else {
//Setting values for tabel columns
$dadossessao = array(
'hora' =>$this->input->post('hora'),
'sala_id'=>$this->input->post('salas'),
'tipo_filme_id'=>$this->input->post('tipofilme'),
'filme_id'=>$this->input->post('filmes')
);
//Transfering data to Model
$this->insert_model1->form_insert($dadossessao);
$dadosessao['message'] = 'Dados Foram Inseridos com Sucesso';
//Loading View
$this->render('admin/inserirsessao');
}
}
}
?>
模型
<?php
class insert_model1 extends CI_Model{
function __construct() {
parent::__construct();
}
function form_insert( $dadossessao){
$this->db->insert('session', $dadossessao);
return $dadossessao;
}
}
?>
我已经花了数小时试图解决问题,但是我不知道发生了什么,有人可以帮我吗?
最佳答案
将表单操作更改为<?php echo form_open('inserirsessao/sessao'); ?>
。
关于php - 代码点火器未将选择元素发送到数据库,并且未显示任何错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41510149/