php – a log in function keep on sending to the wrong url/page even tho i log in correctly

So i made a simple login system and my problem is that it keeps on sending me to login.php?error=wrongpassword and that means i entered the wrong password even tho i logged in the correct password and the correct username

my codes look like this

function uidExists($conn, $username) {
   $sql = "SELECT * FROM highscore WHERE username = ?;";
   $stmt = mysqli_stmt_init($conn);
   if (!mysqli_stmt_prepare($stmt, $sql)) {
     header("location: signup.php?error=usernametaken");

   mysqli_stmt_bind_param($stmt, "s", $username);

   $resultData = mysqli_stmt_get_result($stmt);

   if ($row = mysqli_fetch_assoc($resultData)) {
     return $row;

else {
    $result = false;
    return $result;


function loginUser($conn, $username, $pwd) {
      $uidExists = uidExists($conn, $username );
      if ($uidExists === false) {
        header("location: login.php?error=wrongusername");
      $pwdHashed = $uidExists ("password");
      $checkPwd = password_verify($pwd, $pwdHashed);
      if ($checkPwd === false) {
        header("location: login.php?error=wrongpassword");
      else if ($checkPwd === true) {
        $_SESSION("userid") = $uidExists ("userid");
        $_SESSION("username") = $uidExists ("username");
        header("location: index2.php");

heres my login.php

<!DOCTYPE html>
    <meta charset="utf-8">
  <h2>Log In</h2>
  <form action="" method="POST">
    <input type="text" name="username" placeholder="Username...">
    <input type="password" name="pwd" placeholder="Password...">
    <button type = "submit" name="submit">Sign Up</button>

and heres my


if (isset($_POST("submit"))) {
    $username = $_POST("username");
    $pwd = $_POST("pwd");

  require_once '';
  require_once '';

    if (emptyInputLogin($username, $pwd) !== false){
    header("location: login.php?error=emptyinput");

  loginUser($conn, $username, $pwd);

else {
    header("location: login.php");


This how my database looks like

 userid | username | password | score
    1   |    123   |    123   |   1
    2   |    312   |    312   |   3

I tried checking if I type the column name from the database wrong but no i typed it correctly.
I also tried making a new username and password and logged that in but still the same result.

Credits to the youtuber name Dani Krossing i got all this codes from him.