hi i have a problem about adding data into two tables, heres the situation, i want to add a student with his username and password in users table and his personal info like name and age into users_profiles,, heres my code:
function add_user($username,$password,$fname,$lname,$sex,$address,$city,$country,$role)
{
$this->db->trans_start();
$user = array(
'usrName'=>$username,
'usrPassword'=>sha1($password),
'roleID'=>$role
);
$this->db->insert('users', $user);
$this->db->query('SELECT usrID FROM users WHERE usrName=$username');
$usrID = $this->db->get(); //i know this is wrong thats why i need help
$user_profile = array(
'usrpFirstName'=>$fname,
'usrpLastName'=>$lname,
'usrpSex'=>$sex,
'usrpAddress'=>$address,
'usrpCity'=>$city,
'usrpState'=>$country,
'usrID'=>**$usrID** // this is the foreign key from users table
);
$this->db->insert('users_profiles', $user_profile);
$this->db->trans_complete();
}
You do not need to use
get()when you use thequery()method. Instead store the result from thequery()method and useresult()orrow()to access the data.So your code should be something like: