【问题标题】:Check information double table检查信息双表
【发布时间】:2019-03-03 18:52:09
【问题描述】:

如何在继续注册到结构之前检查表中是否存在字符名称、表>字符>字符 老字号

【问题讨论】:

  • 我想让它检查是否有人已经存在使用相同的名字,它不允许在表中注册
  • 请向我们展示您的型号代码,以便我们为您提供帮助
  • 好吧,我的模态是

标签: php codeigniter email


【解决方案1】:

在插入新记录之前检查数据库中的名称

$data = array(
    "id_username" => $this->session->id_account,
    "name_character" => $nome,
    "birthdate" => $data,
    "origin" => $origem,
    "gender" => $sexo,
    "pergunta1" => $pergunta3,
    "pergunta2" => $pergunta4,
    "history" => $history
);
$if_exists = $this->usuarios_model->check_user($data['name_character']);

//Here apply condition to check if user is exists or not
if($if_exists > 0){
    //Already Exists
}else{
    $this->usuarios_model->criarPersonagem($data); //New registration
}

型号

public function check_user($name_character){

    //Here, get the number if rows with the new user name
    return $this->db->get_where('characters', ['Character' => $name_character])->num_rows();
}

【讨论】:

  • 消息:语法错误,意外的 '=>' (T_DOUBLE_ARROW),需要 ',' 或 ')'
  • @PedroHB 抱歉回复晚了。固定
  • @PedroHB 你在文件的某处缺少curly bracket
  • error > 错误号:1054 'where 子句'中的未知列 'name_character' SELECT * FROM characters WHERE name_character = 'pedro_henrique'
  • 根据您的问题,您的列名是name_character。确保此处的名称正确['name_character' => $name_character]
【解决方案2】:

控制者:

$flag = $this->usuarios_model->criarPersonagem($data);
if($flag == 1){
    redirect("painel/sucesso"); // lembrar de criar a mensagem sucesso!
}else{
    redirect("painel/fracasso"); // lembrar de criar a mensagem fracasso!
}

型号:

function criarPersonagem($data){
      $query = $this->db->get_where('characters',array('name_character'=>$data['name_character']));
      if ($query->num_rows() > 0) {
         return 0;
      }else{
         //register code
         return 1;
      }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多