Php 注册数据未插入Codeigniter中的数据库?重定向不工作?
我正在尝试创建一个简单的注册表单,但在将表单中的数据添加到数据库时遇到问题?我做了哪些不正确的事情,导致数据无法发布到我的用户表 如果验证失败,简单地再次加载视图是否也是不正确的做法?使用重定向失败,并说我应该尝试清除我的cookies 我的代码如下 注册控制器:Php 注册数据未插入Codeigniter中的数据库?重定向不工作?,php,codeigniter,Php,Codeigniter,我正在尝试创建一个简单的注册表单,但在将表单中的数据添加到数据库时遇到问题?我做了哪些不正确的事情,导致数据无法发布到我的用户表 如果验证失败,简单地再次加载视图是否也是不正确的做法?使用重定向失败,并说我应该尝试清除我的cookies 我的代码如下 注册控制器: class Signup extends CI_Controller { public function index() { $this->load->view('templates/header'); $this
class Signup extends CI_Controller
{
public function index()
{
$this->load->view('templates/header');
$this->load->view('signup');
$this->load->view('templates/footer');
}
function signup_validation() {
$this->form_validation->set_rules('first_name', 'First Name', 'required');
$this->form_validation->set_rules('last_name', 'Last Name', 'required');
$this->form_validation->set_rules('username', 'Username', 'required|alpha_numeric|min_length[4]|is_unique[users.username]');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[6]');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required|min_length[6]|matches[password]');
if ($this->form_validation->run()) {
$this->load->model('signup_model');
redirect('login');
}
else {
$this->load->view('templates/header');
$this->load->view('signup');
$this->load->view('templates/footer');
}
}
}
class Signup_model extends CI_Model {
public function index()
{
$url = url_title($this->input->post('user'), 'dash', true);
$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password')
);
return $this->db->insert('users', $data);
}
}
<form action="<?php echo site_url('signup/signup_validation') ?>" method="POST">
<h5>First Name</h5>
<input type="text" name="first_name" value="" />
<span><?php echo form_error('first_name'); ?></span>
<h5>Last Name</h5>
<input type="text" name="last_name" value="" />
<span><?php echo form_error('last_name'); ?></span>
<h5>Username</h5>
<input type="text" name="username" value="" />
<span><?php echo form_error('username'); ?></span>
<h5>Email Address</h5>
<input type="text" name="email" value="" />
<span><?php echo form_error('email'); ?></span>
<h5>Password</h5>
<input type="text" name="password" value="" />
<span><?php echo form_error('password'); ?></span>
<h5>Password Confirm</h5>
<input type="text" name="passconf" value="" />
<span><?php echo form_error('passconf'); ?></span>
<div><input type="submit" value="Register" /></div>
</form>
注册模式:
class Signup extends CI_Controller
{
public function index()
{
$this->load->view('templates/header');
$this->load->view('signup');
$this->load->view('templates/footer');
}
function signup_validation() {
$this->form_validation->set_rules('first_name', 'First Name', 'required');
$this->form_validation->set_rules('last_name', 'Last Name', 'required');
$this->form_validation->set_rules('username', 'Username', 'required|alpha_numeric|min_length[4]|is_unique[users.username]');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[6]');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required|min_length[6]|matches[password]');
if ($this->form_validation->run()) {
$this->load->model('signup_model');
redirect('login');
}
else {
$this->load->view('templates/header');
$this->load->view('signup');
$this->load->view('templates/footer');
}
}
}
class Signup_model extends CI_Model {
public function index()
{
$url = url_title($this->input->post('user'), 'dash', true);
$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password')
);
return $this->db->insert('users', $data);
}
}
<form action="<?php echo site_url('signup/signup_validation') ?>" method="POST">
<h5>First Name</h5>
<input type="text" name="first_name" value="" />
<span><?php echo form_error('first_name'); ?></span>
<h5>Last Name</h5>
<input type="text" name="last_name" value="" />
<span><?php echo form_error('last_name'); ?></span>
<h5>Username</h5>
<input type="text" name="username" value="" />
<span><?php echo form_error('username'); ?></span>
<h5>Email Address</h5>
<input type="text" name="email" value="" />
<span><?php echo form_error('email'); ?></span>
<h5>Password</h5>
<input type="text" name="password" value="" />
<span><?php echo form_error('password'); ?></span>
<h5>Password Confirm</h5>
<input type="text" name="passconf" value="" />
<span><?php echo form_error('passconf'); ?></span>
<div><input type="submit" value="Register" /></div>
</form>
注册视图:
class Signup extends CI_Controller
{
public function index()
{
$this->load->view('templates/header');
$this->load->view('signup');
$this->load->view('templates/footer');
}
function signup_validation() {
$this->form_validation->set_rules('first_name', 'First Name', 'required');
$this->form_validation->set_rules('last_name', 'Last Name', 'required');
$this->form_validation->set_rules('username', 'Username', 'required|alpha_numeric|min_length[4]|is_unique[users.username]');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[6]');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required|min_length[6]|matches[password]');
if ($this->form_validation->run()) {
$this->load->model('signup_model');
redirect('login');
}
else {
$this->load->view('templates/header');
$this->load->view('signup');
$this->load->view('templates/footer');
}
}
}
class Signup_model extends CI_Model {
public function index()
{
$url = url_title($this->input->post('user'), 'dash', true);
$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password')
);
return $this->db->insert('users', $data);
}
}
<form action="<?php echo site_url('signup/signup_validation') ?>" method="POST">
<h5>First Name</h5>
<input type="text" name="first_name" value="" />
<span><?php echo form_error('first_name'); ?></span>
<h5>Last Name</h5>
<input type="text" name="last_name" value="" />
<span><?php echo form_error('last_name'); ?></span>
<h5>Username</h5>
<input type="text" name="username" value="" />
<span><?php echo form_error('username'); ?></span>
<h5>Email Address</h5>
<input type="text" name="email" value="" />
<span><?php echo form_error('email'); ?></span>
<h5>Password</h5>
<input type="text" name="password" value="" />
<span><?php echo form_error('password'); ?></span>
<h5>Password Confirm</h5>
<input type="text" name="passconf" value="" />
<span><?php echo form_error('passconf'); ?></span>
<div><input type="submit" value="Register" /></div>
</form>
您已加载模型,但未加载函数
您已经加载了模型,但没有加载函数
您已经调用了模型,但没有调用加载模型的函数。请尝试添加$this->signup_model->index()代码>也是这样!非常感谢。您已经调用了模型,但没有调用加载模型的函数。请尝试添加$this->signup_model->index()代码>也是这样!非常感谢。