I need a second pair of eyes to have a look at my code and tell me what I am missing, as I think I have identified the portion of code that doesn't work, I just don't know why.
Basically I am trying to register a user to a database, in a way that it prevents SQL injection. For the life of me however, it doesn't work. When I deconstruct the code and make it less secure, it works. Anyway, code is here:
//require_once 'sendEmails.php'; 
session_start();
$username = "";
$email = "";
$user_dob = "";
$user_fname = "";
$user_lname = "";
$user_telephone = "";
$errors = [];
$servername = '';
$login = '';
$password = '';
$DBname = '';
$rows = 0;
$query = "";
$conn = new mysqli($servername, $login, $password, $DBname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
if ($conn) {
  echo "Connected successfully";
}
// SIGN UP USER
if (isset($_POST['signup-btn'])) {
    if (empty($_POST['username'])) {
        $errors['username'] = 'Username required';
    }
    if (empty($_POST['email'])) {
        $errors['email'] = 'Email required';
    }
    if (empty($_POST['password'])) {
        $errors['password'] = 'Password required';
    }
    if (isset($_POST['password']) && $_POST['password'] !== $_POST['passwordConf']) {
        $errors['passwordConf'] = 'The two passwords do not match';
    }
    if (empty($_POST['dob'])) {
        $errors['dob'] = 'Date of birth required';
    }
    if (empty($_POST['fname'])) {
        $errors['fname'] = 'First name required';
    }
    if (empty($_POST['lname'])) {
        $errors['lname'] = 'Last name required';
    }
    if (empty($_POST['telephone'])) {
        $errors['telephone'] = 'Telephone number required';
    } //--checks input in browser
    //I think it works untill this point...
    $token = bin2hex(random_bytes(50)); // generate unique token
    $username = $_POST['username'];
    $password = password_hash($_POST['password'], PASSWORD_BCRYPT); //encrypt password
    $user_dob = $_POST['dob'];
    $user_fname = $_POST['fname'];
    $user_lname = $_POST['lname'];
    $user_telephone = $_POST['telephone'];
    $email = $_POST['email'];
    //Above assigns inputted values into variables declared at the start
    //echo $token, $email; //-- this works
    //nl2br() ; // -- line break in php
    // Check if email already exists
    //$result = $mysqli->query("SELECT * FROM User_tbl WHERE email='$email' LIMIT 1");
    $sql = "SELECT * FROM User_tbl WHERE email='$email' LIMIT 1";
    $result = mysqli_query($conn, $sql);
    if (mysqli_num_rows($result) > $rows) {
              $errors[] = $email;
        echo "Email already exists";
    }
    $errorsInt = count($errors);
    echo mysqli_num_rows($result);
    echo count($errors);
    echo $errorsInt;
    if ($errorsInt === $rows) {
        $query = "INSERT INTO User_tbl SET token=?, username=?,  password=?, user_dob=?, user_fname=?, user_lname=?, user_telephone=?, email=?";
      // "INSERT INTO User_tbl VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
        echo $query;
    //---------------------------------------------------------------------------
        $stmt = $conn->prepare($query); //first
        $stmt->bind_param('sssissis', $token, $username, $password, $user_dob, $user_fname, $user_lname, $user_telephone, $email);
        $result = $stmt->execute();
        echo $result;
            if ($result) {
                $user_id = $stmt->insert_id;
                $stmt->close();
                $_SESSION['id'] = $user_id;
                $_SESSION['username'] = $username;
                $_SESSION['email'] = $email;
                $_SESSION['verified'] = false;
                $_SESSION['message'] = 'You are logged in!';
                $_SESSION['type'] = 'alert-success';
                header('location: index.php');
            } else {
                $_SESSION['error_msg'] = "Database error: Could not register user";
            }
        }
}
The problem I believe starts here:
$stmt = $conn->prepare($query); //first
        $stmt->bind_param('sssissis', $token, $username, $password, $user_dob, $user_fname, $user_lname, $user_telephone, $email);
        $result = $stmt->execute();
