我开始在codeigniter中编码,在提交按钮后,数据应插入数据库并重定向到下一页。对我来说,插入数据库已成功完成,但页面没有重定向; 这是我的控制器 - Home.php
但是我收到错误,因为在此服务器上找不到请求的URL /代码/显示。
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('demo');
//$this->load->model('Insert_data');
}
public function savedata()
{
if($this->input->post('submit'))
{
$data=array(
'name'=>$this->input->post('name'),
'email'=>$this->input->post('email'),
'content'=>$this->input->post('content'));
$result=$this->Insert_data->saverecords($data);
if ($result)
{
echo "Records Saved Successfully";
redirect(base_url().'Home/display');
}
else
{
echo "Records not Saved Successfully";
}
}
}
public function display()
{
$this->load->view('display');
}
}
答案 0 :(得分:0)
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('demo');
//$this->load->model('Insert_data');
}
public function savedata()
{
if($this->input->post('submit'))
{
$data=array(
'name'=>$this->input->post('name'),
'email'=>$this->input->post('email'),
'content'=>$this->input->post('content'));
$result=$this->Insert_data->saverecords($data);
if ($result==1)
{
echo "Records Saved Successfully";
redirect('Home/display');
}
else
{
echo "Records not Saved Successfully";
}
}
}
public function display()
{
$this->load->view('display');
}
}