if语句在运行时未按下codeigniter中的Submit按钮

时间:2018-10-23 06:05:21

标签: codeigniter-3

我希望我的if语句仅在按下提交按钮后才显示插入成功或失败,但是一旦加载函数主管理员admin,显示插入失败。我的代码有什么问题。

       public function masteradmin(){  
        $data = $this->session->all_userdata();
        $this->load->view('user/layout/header',array('data'=>$data));
        $this->load->view('user/layout/left_navbar',array('data'=>$data));
        $this->load->view('user/appconfig/masteradmin');

        $this->load->view('user/layout/footer');
          $post= $this->input->post();
          unset ($post['submit']);
          $this->load->model('AppconfigModel');

            if ($this->AppconfigModel->insert_masteradmin($post))
            {
                echo "insert successfull";
            }

            else
            {
                echo "insert failed";
            }`

1 个答案:

答案 0 :(得分:0)

尝试

如果form submit and post have value that time only it will execute

$post= $this->input->post();
if($post){
    unset ($post['submit']);
    $this->load->model('AppconfigModel');

    if ($this->AppconfigModel->insert_masteradmin($post))
    {
      echo "insert successfull";
    }
    else
    {
      echo "insert failed";
    }
}