【问题标题】:Codeigniter: This page isn’t working localhost is currently unable to handle this request. HTTP ERROR 500 [closed]Codeigniter:此页面不工作 localhost 当前无法处理此请求。 HTTP 错误 500 [关闭]
【发布时间】: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错误,这是由于找不到函数名而发生的。快速检查一下,您是否正确加载了 modellibraries
  • @cyberrspiritt 绝对是先生。你是对的,模型没有正确加载,我需要知道的第二件事是,如果你在控制器和模型中保持相同的函数名称,这也会导致错误 500?

标签: php codeigniter model-view-controller


【解决方案1】:

您需要向我们提供更多信息,而不仅仅是 500 响应代码。检查您的错误日志,并更新您的问题。

为获得最佳错误记录体验,请将 error_reporting 设置为 -1,关闭 display_errors,并设置自定义 error_log。然后在终端中输入tail -f /path/to/error_log。您的通知、警告和错误现在将实时滚动过去,而不会扭曲您的网页显示。

快速的方法是在脚本顶部添加ini_set('display_errors', 'On');

【讨论】:

  • 让我试试吧..!!
  • 加油! :-) 发布您的错误
  • ini_set('display_errors', 1);这可以获取日志
  • @sunilKV 这不是最好的方法,任何通知或警告都会阻止任何header() 呼叫的发生,这就是为什么最好关闭它并在终端中跟踪日志
猜你喜欢
  • 2017-12-19
  • 2017-03-06
  • 2019-01-02
  • 2022-06-18
  • 2020-03-01
  • 2022-06-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多