【问题标题】:form is not sending data using codeigniter表单未使用 codeigniter 发送数据
【发布时间】:2018-04-05 00:24:09
【问题描述】:

我想使用代码点火器将数据保存到数据库中。但是发送数据时出现问题。实际上,表单没有发送数据。我用 print_r() 检查它。 这是我的带有控制器和模型的表格。 请检查它并给我一个正确的解决方案。

查看

   <!DOCTYPE html>
<html>
<head></head>
<body>
<form method="post" action="<?php echo base_url()?
>index.php/c_autoapp/insert_tech" >
<input type="text" name="f_name" >
<input type="text" name="l_name" >
<input type="text" name="user_name" >
<input type="password" name="password" >
<input type="text" name="address" >
<input type="text" name="account" >
<input type="text" name="phone" >
<input type="email" name="email" >
<input type="text" name="status" >
<input type="submit" value="Submit" name="submit">
</form>
</body>
</html>

控制器

这是我的控制器。

 function insert_tech()
    {
        $this->m->insert_tech();

    }

我检查了数据库中的表名和所有列名。这些都可以。

型号

  function insert_tech()
        {   
            if($this->input->post('submit'))
            {
            $f_name=$this->input->post('f_name');
            $l_name=$this->input->post('l_name');
            $user_name=$this->input->post('user_name');
            $password=$this->input->post('password');
            $address=$this->input->post('address');
            $account=$this->input->post('account');
            $phone=$this->input->post('phone');
            $email=$this->input->post('email');
            $status=$this->input->post('status');
            $arr = array('l_name'=>$l_name,
                         'f_name'=>$f_name,
                         'user_name'=>$user_name,
                         'password'=>$password,
                         'address'=>$address,
                         'account'=>$account,
                         'phone'=>$phone,
                         'email'=>$email,
                         'status'=>$status
            );
           $this->db->insert('tb_tech', $arr);
            }
        }

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    在您的控制器中添加 __constructor 函数并打印您的帖子数据。

    public function __constructor()
        {
            $this->load->helper('url');
            $this->load->helper('form');
        }
    public function insert_tech()
        {
    
            print_r($this->input->post());
        }
    

    表单助手按表单打印所有帖子数据。

    【讨论】:

    • 函数 __construct(){ parent::__construct(); $this->load->helper('url'); $this->load->helper('form'); $this->load->model('M_autoapp','m'); }
    • 兄弟!这是我的构造函数。使用 post 方法无法正常工作。使用 get 方法运行良好。
    【解决方案2】:

    在您的控制器中验证您的$this-&gt;input-&gt;post(),而不是在模型中

    控制器

    function insert_tech(){
           if($this->input->post('submit')){
                $f_name=$this->input->post('f_name');
                $l_name=$this->input->post('l_name');
                $user_name=$this->input->post('user_name');
                $password=$this->input->post('password');
                $address=$this->input->post('address');
                $account=$this->input->post('account');
                $phone=$this->input->post('phone');
                $email=$this->input->post('email');
                $status=$this->input->post('status');
                $arr = array('l_name'=>$l_name,
                             'f_name'=>$f_name,
                             'user_name'=>$user_name,
                             'password'=>$password,
                             'address'=>$address,
                             'account'=>$account,
                             'phone'=>$phone,
                             'email'=>$email,
                             'status'=>$status
                );
            $this->m->insert_tech($arr);
            }
    }
    

    型号

    function insert_tech($arr){ 
        $this->db->insert('tb_tech', $arr);
    }
    

    【讨论】:

    • 我在控制器中使用了 print_r() 函数。这显示了空白页。
    • 它对我有用。你有没有在控制器函数的第一行使用print_r($this-&gt;input-&gt;post());
    猜你喜欢
    • 2016-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-14
    • 2018-09-24
    • 1970-01-01
    • 2011-02-25
    • 1970-01-01
    相关资源
    最近更新 更多