2017-05-07 59 views
1

我正在使用CodeIgniter。我有一个表格可以在数据库中输入数据,但是我在这里遇到了一个问题:在codeigniter中的field list中的未知列Student_Name。我已经尝试过,但目前为止我还无法解决。codeigniter中“字段列表”中的未知列'Student_Name'文件名:E:/xampp/htdocs/codeIgniter/CodeIgniter-3.1.4/system/database/DB_driver.php

这是我的代码。

查看文件 Userinsert_view.php

<html> 
<head> 
<title>Insert Data Into Database Using CodeIgniter Form</title> 
</head> 
<body> 

<div id="container"> 
<?php echo form_open('Userinsert_controller'); ?> 
<h1>Insert Data Into Database Using CodeIgniter</h1><hr/> 
<?php if (isset($message)) { ?> 
<CENTER><h3 style="color:green;">Data inserted successfully</h3></CENTER><br> 
<?php } ?> 
<?php echo form_label('Student Name :'); ?> <?php echo form_error('dname'); ?><br /> 
<?php echo form_input(array('id' => 'dname', 'name' => 'dname')); ?><br /> 

<?php echo form_label('Student Email :'); ?> <?php echo form_error('demail'); ?><br /> 
<?php echo form_input(array('id' => 'demail', 'name' => 'demail')); ?><br /> 

<?php echo form_label('Student Mobile No. :'); ?> <?php echo form_error('dmobile'); ?><br /> 
<?php echo form_input(array('id' => 'dmobile', 'name' => 'dmobile', 'placeholder' => '10 Digit Mobile No.')); ?><br /> 

<?php echo form_label('Student Address :'); ?> <?php echo form_error('daddress'); ?><br /> 
<?php echo form_input(array('id' => 'daddress', 'name' => 'daddress')); ?><br /> 

<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit')); ?> 
<?php echo form_close(); ?><br/> 
<div id="fugo"> 

</div> 
</div> 
</body> 
</html> 

控制器文件 Userinsert_controller.php

<?php 

class Userinsert_controller extends CI_Controller { 

    function __construct() { 
     parent::__construct(); 
     $this->load->model('Userinsert_model'); 
    } 

    function index() { 
     //Including validation library 
     $this->load->library('form_validation'); 

     $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); 

     //Validating Name Field 
     $this->form_validation->set_rules('dname', 'Username', 'required|min_length[5]|max_length[15]'); 

     //Validating Email Field 
     $this->form_validation->set_rules('demail', 'Email', 'required|valid_email'); 

     //Validating Mobile no. Field 
     $this->form_validation->set_rules('dmobile', 'Mobile No.', 'required|regex_match[/^[0-9]{10}$/]'); 

     //Validating Address Field 
     $this->form_validation->set_rules('daddress', 'Address', 'required|min_length[10]|max_length[50]'); 

     if ($this->form_validation->run() == FALSE) { 
      $this->load->view('Userinsert_view'); 
     } else { 
      //Setting values for tabel columns 
      $data = array(
       'Student_Name' => $this->input->post('dname'), 
       'Student_Email' => $this->input->post('demail'), 
       'Student_Mobile' => $this->input->post('dmobile'), 
       'Student_Address' => $this->input->post('daddress') 
      ); 
      //Transfering data to Model 
      $this->Userinsert_model->form_insert($data); 
      $data['message'] = 'Data Inserted Successfully'; 
      //Loading View 
      $this->load->view('Userinsert_view', $data); 
     } 
    } 

} 

?> 

型号文件 Userinsert_model.php

<?php 

class Userinsert_model extends CI_Model{ 

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

    function form_insert($data){ 
     // Inserting in Table(students) of Database(college) 
     $this->db->insert('students', $data); 
    } 
} 

?> 
+0

尝试匹配数据库中的字段名称。检查它是否有资本。通过数据库中的确切字段名称 – Exprator

回答

1

您在将值传递到期望的数据库列时出错。确保$数据阵列的主要有相同的列名存在于数据库表:

$data = array('Student_Name' => $this->input->post('dname'), 'Student_Email' => $this->input->post('demail'), 'Student_Mobile' => $this->input->post('dmobile'), 'Student_Address' => $this->input->post('daddress')); 

您在Student_name指数传递的价值,它必须存在于表。小心区分大小写的列名称。

让我知道你是否仍然面临这个问题。

+0

oo yess !!你绝对是现货!谢谢非常多@abhishek singh –

+0

欢迎好友! –

相关问题