这是我的cotroller代码
public function registration(){
$this->load->model('user_model');
$result_data['count']=$this->user_model->count_batch_student();
if($_POST){
$data=array(
"first_name"=> $this->input->post('fname'),
"last_name"=> $this->input->post('lname'),
"dob"=> $this->input->post('dob'),
"gender"=> $this->input->post('gender'),
"email"=> $this->input->post('email'),
"mob"=> $this->input->post('mob'),
"course"=>$this->input->post('course'),
"batch"=>$this->input->post('batch'),
"address"=>$this->input->post('address'),
"city"=>$this->input->post('city'),
"state"=>$this->input->post('state'),
"pin"=>$this->input->post('pin'),
"address"=>$this->input->post('address'),
);
$result_data['user_result']=$this->user_model->register_data($data);
}
$this->load->view('sunnon_registration', $result_data);
}
这是我的模型代码,首先我正在检查电子邮件ID是否已存在如果它存在我只是更新表,如果不存在那么我将数据插入表中。
public function register_data($data){
extract($data);
$query="select * from a3m_account where email='$email'";
$result=$this->db->query($query);
if($result->num_rows()>0){
$query="update a3m_account set first_name='$first_name', last_name='$last_name', dob='$dob',gender='$gender',email='$email',contact_num='$mob', address='$address', city='$city',state='$state', pin='$pin', course='$course', batch='$batch'";
$this->db->query($query);
return "User already exist";
}else{
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?";
$password = substr( str_shuffle( $chars ), 0, 5);
$query="insert into a3m_account (first_name, last_name, dob, gender,email, contact_num, address, city, state, pin, course, batch, password ) values('$first_name', '$last_name', '$dob', '$gender', '$email', '$mob', '$address', '$city', '$state', '$pin', '$course', '$batch', '$password')";
$this->db->query($query);
$query="select email, password, id from a3m_account where email='$email'";
$result= $this->db->query($query);
if($result->num_rows()> 0){
return $result-> result("array");
}
}
}
无论何时,我都会将错误视为可变未定义
答案 0 :(得分:0)
尝试使用$data = array()
中的register_data($data = array())
代替提取($ data);
public function register_data($data = array()) {
$message = array();
$this->db->select('*');
$this->db->from('a3m_account');
$this->db->where('email', $data['email']);
$query = $this->db->get();
if($query->num_rows() >0 ){
$update_info = array(
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'dob' => $data['dob'],
'gender' => $data['gender'],
'email' => $data['email'],
'contact_num' => $data['mob'],
'address' => $data['address'],
'city' => $data['city'],
'state' => $data['state'],
'pin' => $data['pin'],
'course' => $data['course'],
'batch' => $data['batch']
);
$this->db->where('id', $query->row()->id);
$this->db->update('a3m_account');
$message = 'User all ready exists';
}else{
$new_password = password_hash($data['password'], PASSWORD_DEFAULT);
$insert_info = array(
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'dob' => $data['dob'],
'gender' => $data['gender'],
'email' => $data['email'],
'contact_num' => $data['mob'],
'address' => $data['address'],
'city' => $data['city'],
'state' => $data['state'],
'pin' => $data['pin'],
'course' => $data['course'],
'batch' => $data['batch'],
'password' => $new_password
);
$this->db->set($insert_info);
$this->db->insert('a3m_account');
$message = 'New User';
}
return $message;
}
创建密码哈希。密码列确保varchar 255
在您的登录功能上,使用以下内容验证密码
http://php.net/manual/en/function.password-hash.php
控制器
public function registration(){
$created = '';
$this->load->model('user_model');
$result_data['count'] = $this->user_model->count_batch_student();
if($_POST){
$data = array(
"first_name"=> $this->input->post('fname'),
"last_name"=> $this->input->post('lname'),
"dob"=> $this->input->post('dob'),
"gender"=> $this->input->post('gender'),
"email"=> $this->input->post('email'),
"mob"=> $this->input->post('mob'),
"course"=>$this->input->post('course'),
"batch"=>$this->input->post('batch'),
"address"=>$this->input->post('address'),
"city"=>$this->input->post('city'),
"state"=>$this->input->post('state'),
"pin"=>$this->input->post('pin'),
"address"=>$this->input->post('address'),
);
$created = $this->user_model->register_data($data);
}
$result_data['message'] = $created;
$this->load->view('sunnon_registration', $result_data);
}
查看
<?php echo $message;?>