猿问

当我在数据库名称中插入数据时,我的代码有什么问题是 db2 它给了我一个错误列“名称”不能为空

我想在数据库名称db2中插入数据表名称table1来自注册表,但它给我以下错误,因为“列Name不能为空”,我不明白,请帮助我


我的控制器名称是Abc.php,代码是


<?php

defined('BASEPATH') OR exit ('No direct script access allowed');

class Abc extends CI_Controller {

public function index(){


      $this->load->database();

      $this->load->model('Done');

      $this->load->view('codingregi');


                        $data = array(  

                        'Name'     => $this->input->post('name'),  

                        'Email'  => $this->input->post('email'),  

                        'Password' => $this->input->post('password'), 

                        'Gender'   => $this->input->post('gender')  


                        );  

         $this->Done->savingdata($data);

         redirect('Abc/index'); 



      }

}

?>

型号名称是Done.php和是


 <?php

    defined('BASEPATH') OR exit ('No direct script access allowed');

    class Done extends CI_Model

     {

     public function savingdata($data)  

        {  

            //this array is used to get fetch data from the view page.  

         //$xyz = "insert into table1 values ('$name','$email','$password','$gender')";

      //$this->db->query($xyz);  

     {

          $this->db->insert('table1',$data);

          $emp_id = $this->db->insert();

        } 

        return emp_id;

        }

    }

    ?>

和注册表名称是 codingregi.php


 <!DOCTYPE html>

    <html>

    <head>

    <title>registraion form</title>

    </head>

    <body>

    <form method="POST" method="Abc.php">

    Name:<input type = "text" name="name"><br></br>

    email: <input type = "email" name="email"><br></br>

    Password: <input type ="password" name="password"><br></br>

    Gender: <input type ="radio" name="gender" value="male">Male

            <input type ="radio" name="gender" value="female">Female<br></br>


    <input type ="submit">

    </form>

    </body>

以下是完整的错误描述


错误编号:1048


列“名称”不能为空


INSERT INTO table1( Name, Email, Password, Gender) 值 (NULL, NULL, NULL, NULL)


文件名:C:/xampp/htdocs/CodeIgniter-3.1.10/CodeIgniter-3.1.10/system/database/DB_driver.php


行号:691


有只小跳蛙
浏览 191回答 2
2回答

蓝山帝景

在您的控制器中:<?php&nbsp; &nbsp; defined('BASEPATH') OR exit ('No direct script access allowed');&nbsp; &nbsp; class Abc extends CI_Controller {&nbsp; &nbsp; public function index(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $this->load->view('codingregi');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; public function save(){&nbsp; &nbsp; &nbsp; &nbsp; $this->load->database();&nbsp; &nbsp; &nbsp; &nbsp; $this->load->model('Done');&nbsp; &nbsp; &nbsp; &nbsp; $data = array(&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Name'&nbsp; &nbsp; &nbsp;=> $this->input->post('name'),&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Email'&nbsp; => $this->input->post('email'),&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Password' => $this->input->post('password'),&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Gender'&nbsp; &nbsp;=> $this->input->post('gender')&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; $this->Done->savingdata($data);&nbsp; &nbsp; &nbsp; &nbsp; redirect('Abc/index');&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; ?>在你看来<form method="POST" action="<?= base_url() ?>/abc/save">
随时随地看视频慕课网APP
我要回答