dongling0519 2014-04-10 19:57
浏览 205
已采纳

如何检查用户名是否已被使用,如果没有,请将所选用户名输入MySQL数据库?

I am making a registration system, and I wanted to check wether or not a Username chosen by the user has already been used and if it hasn't already been used, enter the chosen username into the DB?.

below is my query as it is so far, but I keep getting syntax errors. For the record: I am going to use BindParam() to bind the PHP input of the user into the query :)

I also have another column called "ID-number", which is a primary key.

Any help on how to do this is welcome!

Greets,

Romulus


SELECT CASE 
WHEN `Username` != `Username`

THEN

INSERT INTO 'T_Users' `Username`, `Password`, `Email`
VALUES ':username', ':password', ':email'

END

FROM `T_Users`
  • 写回答

2条回答 默认 最新

  • dqkv0603 2014-04-10 20:01
    关注

    you can do something like this

    <?php
    
    $query = mysqli_query($con , "SELECT 1 FROM `T_Users` WHERE username = '$username'");
    if(mysqli_num_rows($query) > 0) {
       echo "Username is already taken";
    } else {
      # Username is available do insert the Data into Database ....
    }
    
    
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记