我想使用codeigniter将数据保存到我的sql中,但是当我点击时 提交按钮,它显示错误页面无法找到....视图文件显示但点击提交按钮它显示下一页错误......... 我的观点文件
add.php
<html>
<head>
<title>Insert Employee Records in Database</title>
</head>
<body>
<form action="<?php echo base_url('emp_add/save'); ?>" method="post">
<table align="center">
<tr>
<td>First Name:</td>
<td><?php echo form_input(array('id'=>'fname', 'name'=>'fname',
'placeholder' => 'First Name', 'size'=>25));?></td>
</tr>
<tr>
<td>Last Name:</td>
<td><?php echo form_input(array('id'=>'lname', 'name'=>'lname',
'placeholder' => '
<tr>lname', 'size'=>25));?></td>
</tr>
<td>Email:</td>
<td><?php echo form_input(array('id'=>'email', 'name'=>'email',
'placeholder' => 'Email', 'size'=>25));?></td>
</tr>
<tr>
<td>Credits:</td>
<td><?php echo form_input(array('id'=>'credits',
'name'=>'credits',
'placeholder' => 'credits', 'size'=>25));?></td>
</tr>
<tr>
<td></td>
<td><button type="submit" id="submit" name="submit" >ADD</button>
</td>
</tr>
</table>
</form>
</body>
</html>
我的控制器文件
emp_addd.php
<?php class Emp_add extends CI_Controller {
public function_construct() {
parent:: _construct();
$this->load->model('employee_model');
$this->load->helper(array('form','url'));
}
public function index()
{
$this->load->view('add'); }
public function save() {
$this->load->model('employee_model');
if($this->input->post('submit'))
{
$this->employee_model->process();
}
redirect('emp_add');
}
我的模型文件
employee_model.php
<?php if (!defined('BASEPATH')) exit('No direct script access
allowed'); class Employee_model extends CI_Model {
public function process()
{
$save = array(
'fname' => $this->input->post('fname'),
'lname' => $this->input->post('lname'),
'email' => $this->input->post('email'),
'credits' => $this->input->post('credits')
);
$this->db->insert('customers',$save);
}
} }
?>
显示页面好。但是提交它会显示错误