php - 检查用户是否已存在的函数
问题描述
我无法让我的功能工作,我有下一个代码
<?php
function alreadyExists($name) {
require_once "connection.php";
$funcsql = "SELECT * FROM `users` WHERE `name` = ?";
$funcstmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($funcstmt, $funcsql);
mysqli_stmt_bind_param($funcstmt, "s", $name);
mysqli_stmt_execute($funcstmt);
$rows = mysqli_stmt_num_rows($funcstmt);
if ($rows > 0 ) {
$error1 = "Already exists";
return $error1;
}
}
?>
它在功能中,这在我的注册中
$error1 = alreadyExists($login);
if (isset($error1)) {
$errors = "User already exists";
}
但它不起作用,无论如何它都会注册你,我的错误在哪里?
解决方案
推荐阅读
- php - 提示登录后如何将 $_POST 数据传递给 youtube 上传脚本
- c# - 将多行字符串转换为多维数组?
- java - 分片接口和后台服务的区别?
- nsis - 如何查询/调试 NSIS 错误?
- javascript - 使用 document.getElementById() 后不显示警报
- jakarta-ee - 注入上下文
- ruby-on-rails - Web 控制台中的 Rails gem devise_token_auth 标头无法访问 api,为什么?
- sql - SQL -SSMS- 将数据从一个表带到另一个表
- javascript - 浏览器使用 history.pushState 前进两步
- javascript - 在 React 中更新喜欢或不喜欢计数器后更新进度条