|
本帖最后由 刀客孩哥 于 2010-8-25 14:24 编辑
model里有这么个函数,负责把表单里的数据弄进数据库
PHP复制代码 function add_user ()
{
$useremail=$this->input->post('useremail');
$password=$this->input->post('password');
$nicheng=$this->input->post('nicheng');
$mysex=$this->input->post('mysex');
$brithyeah=$this->input->post('brithyeah');
//.....略
$query = $this->db->query("SELECT username From dc_user WHERE username = '$useremail'");
if($query->num_rows() > 0)
{
return $useremail;
}
$password = md5($password);
$sql="INSERT INTO user(username,password,nicheng)VALUES('$useremail','$password','$nicheng')";
$query = $this->db->query($sql);
// $new_id_number=$this->db->insert_id();
// $sql2="INSERT INTO user_info VALUES('$new_id_number','$mysex','$brithyeah','$brithmonth','$brithday',
// '$shen','$shi','$shengao','$xueli','$yuexin','$zhufang','$hunkuang','$haizi','$handphone','$buchong')";
// $query2 = $this->db->query($sql2);
if($query && $query2)
{
return $this->db->insert_id();
}else{
return false;
}
} 复制代码
控制器里有这么个函数:是判断用户名是否重复
PHP复制代码 if($this->form_validation->run()==FALSE){
$this->load->view('register');
}else{
$this->load->model('M_user');
$query = $this->M_user->add_user();
if($query == $this->input->post('useremail',TRUE))
{
$data['useremail_exist'] = $this->input->post('useremail');
$this->load->view('register',$data);
}else{
$this->session->set_userdata('useremail',$this->input->post('useremail'));
redirect('Home/user');
}
}
} 复制代码
问题:插入单表是可以的,一切正常。但我的注册表单要分别插入两个表,user和user_info。。我加上model里所注释的代码后,插入数据是成功的,但views里那个对用户名是否重复的判断好像就不灵了。无论重不重复,提交注册表单后都到达regsiter页,正常情况应该是:不重复就进user页
急盼赐教啊! |
|