0

So I'm creating a PHP function which should insert data into a mySQL database. There are no mistakes outside this function, error message says it's in the first line inside the function, "$sql = "INSERT INTO ..."

createUser($conn, $name, $email, $username, $pwd) {
        $sql = "INSERT INTO users (usersName, usersEmail, usersUid, usersPwd) VALUES (?, ?, ?, ?);";
        $stmt = mysqli_stmt_init($conn);

        if (!mysql_stmt_prepare($stmt, $sql)) {
            header("location: ../signup.php?error=stmtfailed");
            exit();
        }

        $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);

        mysqli_stmt_bind_param($stmt, "ssss", $name, $email, $username, $hashedPwd);
        mysqli_stmt_execute($stmt);
        mysqli_stmt_close($stmt);

        header("location: ../signup.php?error=none");
        exit();
    }

I'm using VSCode and XAMPP, if that helps... Hope someone can find something, thanks for searching!

Fubel
  • 3
  • 2
  • 2
    You're missing the `function` keyword before `createUser`. Also, you're missing `mysql_stmt_prepare` instead of `mysqli_stmt_prepare` which will cause other issues. – aynber Jun 23 '21 at 15:47
  • Oh wow, I think I need a break. Thank you so much! – Fubel Jun 23 '21 at 15:48

0 Answers0