【发布时间】:2011-08-26 22:28:52
【问题描述】:
嗨,我在将数据添加到两个表时遇到问题,情况如下,我想在 users 表中添加一个学生,他的用户名和密码以及他的个人信息(如姓名和年龄)到 users_profiles,这是我的代码:
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();
}
【问题讨论】:
标签: php database codeigniter transactions