php - 如何使用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
解决方案
推荐阅读
- powershell - 将 CSV 与包含另一个 CSV 的两列的数组进行比较
- flutter - 如何在 Flutter 中存储离线图片
- reactjs - React Formik 发布特定字段
- cmake - Yocto 中的 CMake 配置文件包 - 安装 Qpid Proton 时出现问题
- angular - 错误 TS2322:类型“对象”不可分配给类型“NgIterable”
'。类型“对象”不可分配给类型“可迭代” ' - python - 在排行榜中显示数据 - Django
- java - Java Regex Group By 不能按预期的数字工作
- powershell - 当我的用户名中有 \ 时,Powershell 脚本不运行
- android-studio - 在 Android Studio 的 Google Drive 上自动保存文件
- discord - discord ActionRow 不是 JSON 可序列化的