|
本帖最后由 zhangcjl 于 2010-4-11 10:55 编辑
贴一下控制器的代码:
<?php
class Register extends Controller{
function Register()
{
parent::Controller();
}
function index()
{
$this->load->helper('form');
$this->load->helper('url');
$sitedata['title']="注册";
$sitedata['headline']="用户注册";
$sitedata['regform']='regform';
$this->load->vars($sitedata);
$this->load->view('regform');
}
function check_reg()
{
$this->load->helper('url');
$reg_config=array
(
array
(
'field'=>'uname',
'label'=>'uname',
'rules'=>'trim|required|min_length[2]|max_length[15]|xss_clean'
),
array
(
'field'=>'passwd',
'label'=>'passwd',
'rules'=>'trim|required|md5|min_length[5]'
),
array
(
'field'=>'repasswd',
'label'=>'repasswd',
'rules'=>'trim|required|matches[passwd]|min_length[5]'
),
array
(
'field'=>'email',
'label'=>'email',
'rules'=>'trim|required|valid_email'
),
array
(
'field'=>'qq',
'label'=>'qq',
'rules'=>'required'
),
array
(
'field'=>'sex',
'label'=>'sex',
'rules'=>'required'
)
);
$this->load->library('form_validation');
$this->form_validation->set_rules($reg_config);
if($this->form_validation->run()==FALSE)
{
echo "注册信息填写有误!请重新填写表单!";
//echo $this->input->ip_address();
//echo $this->input->user_agent();
$this->load->view('regform');
//redirect('register','refresh');
}
else
{
//$this->load->view('regsuccess');
//redirect('register/saveuser','refresh');
if($this->input->post('passwd'))
{
$this->load->helper('url');
$this->load->model('Add_user','',TRUE);
if($this->Add_user->user_add())
{
redirect('register/reg_success');
}
else
{
redirect('register/index','refresh');
//echo "注册失败!请检查你的注册信息或者联系管理员!";
}
}
else
{
$this->load->helper('url');
redirect('register/index','refresh');
//echo "请检查你的注册信息!";
}
}
}
function reg_success(){
$this->load->view('reg_success');
}
}
?>
贴一下model的代码:
<?php
class Add_user extends Model{
function Add_user()
{
parent::Model();
}
function user_add()
{
$now = date("Y-m-d H:i:s");
$user_data=array(
'username'=>$this->input->post('uname'),
'passwd'=>$this->input->post('passwd'),
'email'=>$this->input->post('sex'),
'qq'=>$this->input->post('qq'),
);
$this->db->query("set names 'gbk'");
$this->db->insert('ci_user',$user_data);
//echo "<script language=\"javascript\">alert('注册成功!');</script>";
//echo "<script language=\"javascript\">alert('注册失败!');</script>";
}
}
?>
测试了好久,郁闷,明明数据库都插入成功了,但是这里的跳转
if($this->Add_user->user_add())
{
redirect('register/reg_success');
}
else
{
redirect('register/index','refresh');
//echo "注册失败!请检查你的注册信息或者联系管理员!";
}
这里的跳转总是不能跳转到redirect('register/reg_success'),百思不得其解,郁闷啊~~~~~算了,可能是熬夜脑袋昏了吧,总是会犯一些低级错误的,睡觉先,明天再想想办法~~~~ |
|