首页 > 解决方案 > 检查用户是否已存在的函数

问题描述

我无法让我的功能工作,我有下一个代码

<?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

解决方案


推荐阅读