首页 > 解决方案 > 如何使用Prepared Statements知道用户名是否已经在PHP的数据库中?

问题描述

这是我的代码:

$sql = "SELECT name FROM trainee WHERE username=?";
$stmt = mysqli_stmt_init($con);
if(!mysqli_stmt_prepare($stmt,$sql)){
    header("Location: ../Sign_Up.php?error=SQL_Error");
    exit();
}else{
    mysqli_stmt_bind_param($stmt,"s",$username);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_store_result($stmt);
    $resultCheck=mysqli_stmt_num_rows($stmt);
    if($resultCheck>0){
        header("Location : ../Sign_Up.php?error=usertaken&mail=".$Name);
    }else{
               //Some code
    }
}

错误 :

内部服务器错误

服务器遇到内部错误或配置错误,无法完成您的请求。

请通过 postmaster@localhost 联系服务器管理员,告知他们此错误发生的时间,以及您在此错误之前执行的操作。

服务器错误日志中可能提供有关此错误的更多信息。Apache/2.4.46 (Win64) OpenSSL/1.1.1h PHP/8.0.0 服务器在 localhost 端口 80

标签: phpmysqlerror-handlingphpmyadminprepared-statement

解决方案


推荐阅读