为什么DB获取不到post方法发送的数据?

Why the DB cannot get the data sent by post method?

我正在学习 PHP OOP,但遇到了问题。这是一个真正的初学者代码,我正在练习我的考试,但我被卡住了,所以我需要一些帮助。 我使用 CodeIgniter,数据库库已填充并自动加载。

我有一个表格:用户必须填写姓名、电子邮件和 phone 字段。一个控制器得到它,把它交给应该将数据插入数据库的模型,但我收到一条错误消息:“Column 'trainedName' cannot be null”所以我猜它首先没有得到数据.

视图(简体):

<form action="index.php/aboutme/calling" method="POST" enctype="text/plain">
  <input class="callback" type="text" name="nev" placeholder="Neved:" required>
  <input class="callback" type="email" name="email" placeholder="E-mail címed:"  required>
  <input class="callback" type="tel" name="telszam" placeholder="Telefonszámod (36201234567):"  required>
  <input type="submit">
</form>

控制器:

class Aboutme extends CI_Controller {
public function calling() {
            $datas=array();
            
            $trained = new Callback();
            $trained->addTrained($datas);

            $this->load->view('aboutme');
    }

型号:

class Callback extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    public function addTrained(){

        $na = $this->input->post('nev');
        $em = $this->input->post('email');
        $ph = $this->input->post('telszam');

        $datas = array(
            'trainedName' => $na, 
            'email' => $em, 
            'phone' => $ph
        );   

        $this->db->insert('trained', $datas);
}        

感谢您的帮助!

你说的是enctype="text/plain"。这会导致表单以一种更易于人类阅读但不能被机器可靠地解释的形式提交数据。 PHP 不会为您解析该格式。不要那样做。