0
我試圖通過檢查用戶類型在兩個表中添加信息。如果用戶是普通用戶,則必須在第一個表中輸入記錄,如果用戶類型是醫生,則必須在兩個表中輸入記錄。我工作在笨3.6在CodeIgniter中使用if語句的兩個插入查詢
public function model_signup()
{
$nameVar = $this->input->post("signup_name");
$emailVar = $this->input->post("signup_email");
$phoneVar = $this->input->post("signup_phone");
$passwordVar = $this->input->post("signup_password");
$ifDoctorVar = $this->input->post("signup_ifdoctor");
$pmdcVar = $this->input->post("signup_pmdc");
$signu_query = $this->db->query("SELECT * FROM `doc_users` WHERE `user_email`='".$emailVar."'");
if($signu_query->num_rows() >0){
return false;
}
else
{
$this->db->query("INSERT INTO `doc_users`
(`user_nicename`,
`user_login`,
`user_email`,
`display_name`,
`user_phone`,
`user_pass`,
`user_type`,
`user_registered`)
VALUES ('$nameVar',
'$emailVar',
'$emailVar',
'$nameVar',
'$phoneVar',
'$passwordVar',
'$ifDoctorVar',
NOW())");
$user_id = $this->db->insert_id();
if($ifDoctorVar=='Doctor') { // checking if user is doctor or not
$this->db->query("INSERT INTO `doc_doc_details`
(`ID`,
`pmdc_id`,
`email`,
`phone)
VALUES ('$user_id',
'$pmdcVar',
'$emailVar',
'$phoneVar')");
return true;
}
}
}
什麼錯誤你有? – kc1994
得到2個錯誤,第一個是記錄沒有進入第二個表,第二個是提交後頁面重定向到錯誤頁面 –
當我試着用一個查詢一切工作正常 –