gpt4 book ai didi

php - CodeIgniter 中带有 if 语句的两个插入查询

转载 作者:行者123 更新时间:2023-11-29 21:42:10 26 4
gpt4 key购买 nike

我试图通过检查用户类型在两个表中添加信息。如果用户是普通用户,则必须在第一个表中输入记录,如果用户类型是医生,则必须在两个表中输入记录。我正在使用 CodeIgniter 3.6

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;
}

}
}

最佳答案

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 remove this
}

}
}

关于php - CodeIgniter 中带有 if 语句的两个插入查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34397139/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com