2015-02-06 60 views
0

我有一个简单的表单设置。它显示了很好,当我点击提交看起来像它正在工作,但是当我去检查MSSQL服务器中的数据它不在那里。我不确定它为什么不起作用。codeigniter表单数据没有插入MSSQL数据库

控制器是insert.php

<?php 
class insert extends CI_Controller { 
function __construct() { 
parent::__construct(); 
$this->load->model('insert_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('EmpName', 'Employee_Name', 'required|min_length[3]|max_length[15]'); 
// Validating Email Field 
$this->form_validation->set_rules('Department', 'Department', 'required|min_length[3]|max_length[15]'); 
// Validating Email Field 
$this->form_validation->set_rules('LanID', 'LanID', 'required|min_length[3]|max_length[15]'); 
if ($this->form_validation->run() == FALSE) 
{ 
$this->load->view('insert_view'); 
} 
else 
{ 
// Setting Values For Tabel Columns 
$data = array(
'Employee_Name' => $this->input->post('EmpName'), 
'Department' => $this->input->post('Department'), 
'LanID' => $this->input->post('LanID'), 
); 
// Transfering Data To Model 
$this->insert_model->form_insert($data); 
// Loading View 
$this->load->view('insert_view'); 
} 
} 
} 
?> 

模型insert_model.php

<?php 
class insert_model extends CI_Model{ 
function __construct() { 
parent::__construct(); 
} 
function form_insert($data){ 
// Inserting in Table(requests) of Database(employee) 
$this->db->insert('requests', $data); 
} 
} 
?> 

View是insert_view.php

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

</head> 
<body> 
<div id="container"> 
<?php echo form_open('insert'); ?> 
<h1>Insert Data Into Database Using CodeIgniter</h1> 
<?php echo form_label('Employee Name :'); ?> <?php echo form_error('EmpName'); ?> 
<?php echo form_input(array('id' => 'EmpName', 'name' => 'EmpName')); ?> 
<?php echo form_label('Department :'); ?> <?php echo form_error('Department'); ?> 
<?php echo form_input(array('id' => 'Department', 'name' => 'Department')); ?> 
<?php echo form_label('LanID :'); ?> <?php echo form_error('LanID'); ?> 
<?php echo form_input(array('id' => 'LanID', 'name' => 'LanID')); ?> 
<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit'));?> 
<?php echo form_close(); ?> 
</div> 
</body> 
</html> 

回答

0

你尝试过调试?

在你的控制器:

$data = array(
'Employee_Name' => $this->input->post('EmpName'), 
'Department' => $this->input->post('Department'), 
'LanID' => $this->input->post('LanID'), 
); 

完成所有的数组索引与数据库表的列名完全匹配?

在你的模型:

print_r($data); 

前:

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

如果$数据中包含的数据,尽量设置功能。

$this->db->set('Employee_Name', $EmpName); 
$this->db->set('Department', $Department); 
$this->db->set('LanID', $LanID); 
$this->db->insert('requests'); 

尝试调试......

+0

你是对TY我努力学习,我需要学习更多的调试。我不擅长调试我可能需要在调试时需要一个类 – Donny 2015-02-06 23:15:27

+0

不要弄错......我正在调试一个小问题近30个小时......终于找到了这个小...这是最糟糕的事情在世界上.... – Shuhail 2015-02-06 23:18:44