0
간단한 가입 양식을 만들려고하는데 양식의 데이터를 데이터베이스에 추가하는 데 문제가 있습니까? 데이터가 내 사용자 테이블에 게시되지 않는다는 잘못된 정의는 무엇입니까?가입 데이터가 Codeigniter의 데이터베이스에 삽입되지 않습니까? 리디렉션이 작동하지 않습니까?
유효성 검사가 실패 할 경우 부적절한 작업을 다시로드하는 것입니까? 리디렉션을 사용하면 간단히 실패하고 쿠키를 삭제해야한다고 말했습니다.
내 코드는 다음과 같습니다.
가입하기 컨트롤러 :
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>
없는 함수는 (> signup_model-> 인덱스'$ this- 추가 시도);'https://www.codeigniter.com/user_guide/general/models.html#loading-a-model – user4419336
그게 전부 였어! 고맙습니다! – migs