One user having multiple card ( php, mysql ) -
i have question, trying create way in user logged in can register multiple cards under name. understand concept cannot apply it. need help.
so have 2 tables 1 users , cards, shown.
so created table , of information inserted directly me example orig_id.
so want user logged in can create multiple cards. maybe new_users.id equal user_money.orig_id , not sure how can make them equal each other , when new user registers , enters more cards how can user id , orig id equal each other.
this controller login , controller when user adds card.
public function login(){ $this->load->helper('form'); $this->load->library('form_validation'); $this->form_validation->set_rules('email', 'email', 'required'); $this->form_validation->set_rules('password', 'password', 'required|min_length[4]|max_length[32]'); if ($this->form_validation->run() == false){ $this->load->view('header_view'); $this->load->view('body_view'); $this->load->view('footer_view'); }else{ $email = $this->input->post('email'); $password = $this->input->post('password'); $this->load->model('main_page'); $user_id = $this->main_page->login_user($email, $password); if($user_id){ $user_data = array( 'user_id' => $user_id, 'email' => $email, 'loggedin' => true ); $this->session->set_flashdata('loggedin_success','you loggedin'); redirect('main/admin'); }else{ redirect('main/login'); } } } and function new card getting registered.
public function insertusercard(){ $this->load->helper('form'); $this->load->library('form_validation'); $this->form_validation->set_rules('cardname', 'cardname', 'required'); $this->form_validation->set_rules('iban', 'iban', 'required'); $this->form_validation->set_rules('cc', 'cc', 'required|max_length[4]'); $this->form_validation->set_rules('amount', 'amount', 'required'); if ($this->form_validation->run() == false){ $this->load->view('header_view'); $this->load->view('admin_view'); $this->load->view('footer_view'); }else{ $data = array( 'card_type' => $this->input->post('cardname'), 'iban' => $this->input->post('iban'), 'cc' => $this->input->post('cc'), 'amount' => $this->input->post('amount'), 'orig_id' => 52 /*so orig id here randomly added me */ ); $this->load->model('main_page'); $this->main_page->storecardinfo($data); redirect('main/admin'); } } and incase if needed models both table data being inserted.
public function login_user($email , $password){ $this->db->where('email', $email); $this->db->where('password', $password); $result = $this->db->get('new_users'); if($result ->num_rows() == 1){ return $result->row(0)->id; }else{ return false; } } public function storecardinfo($data){ $insert = $this->db->insert('user_money',$data); return $insert; } so if me on how 1 user have multiple rows in user_money table. using codeigniter , mysql
just use user_id stored $user_data inside of login().
first, make user_data session variable whole controller can access it, change line in login() declares $user_data local variable assign session variable.
change:
$user_id = $this->main_page->login_user($email, $password); if($user_id){ $user_data = array( ...
to:
$user_id = $this->main_page->login_user($email, $password); if($user_id){ $this->session->set_userdata(array( ... then... can change line in insertusercard():
'orig_id' => 52 /*so orig id here randomly added me */
to use session:
'orig_id' => $this->session->userdata('user_id'); i think, since "new this", should perhaps ensure mysql database setup foreign key constraint. (and understand how works)


Comments
Post a Comment