【发布时间】:2018-01-04 13:46:48
【问题描述】:
我正在做一件简单的事情,将一些内容保存在数据库中,但是我如何得到这个 HTTP ERROR 500。我不知道它为什么会出现,而且我的代码也无法正常工作。请看一下
Controller.php
function register_query()
{
//load the registration helper under helper folder
$this->load->helper('registration');
$this->form_validation->set_rules('first_name', 'Name', 'required');
$this->form_validation->set_rules('message1', 'Message', 'required');
$this->form_validation->set_rules('email', 'Email Address', 'required');
if ($this->form_validation->run() == true)
{
$data = array(
'first_name' => $this->input->post('first_name'),
'message1' => $this->input->post('message1'),
'email' => $this->input->post('email'),
);
}
if ($this->form_validation->run() == true && $this->Register_Model->register_query($data))
{
$data['success'] = "Your Query has been sent successfully... !!";
$this->load->view('contact',$data);
}
else
{
$data['success'] = "Your Query has not been sent successfully... !!";
$this->load->view('contact',$data);
}
}
Model.php
public function query($data)
{
$this->db->insert('queries', $data);
$id = $this->db->insert_id();
return (isset($id)) ? $id : FALSE;
}
【问题讨论】:
-
你检查你的日志了吗?
-
是的,先生,我有.. @ArunpandianM 你能告诉我我的代码是否正确吗?
-
尝试@RiggsFolly 的回答需要日志,以便轻松找到错误
-
基本上500(内部服务器错误)的原因基本上是php FATAL错误,这是由于找不到函数名而发生的。快速检查一下,您是否正确加载了 model 和 libraries?
-
@cyberrspiritt 绝对是先生。你是对的,模型没有正确加载,我需要知道的第二件事是,如果你在控制器和模型中保持相同的函数名称,这也会导致错误 500?
标签: php codeigniter model-view-controller