'How to Update SQL Table Where condition is True

PROBLEM: I am trying to UPDATE table data with a "forgot password key" where the email field matches the user's form input on a previous page. I want to make sure the user's input is sanitized and a match can be found in the database.

ERROR: The code does not update the ForgotKey Field in my Database

Here is my code, error is happening on line 7 where stated in the comment.

    $ForgotKeyLength = 9;
    $ForgotKeyString = "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $ForgotKey = substr(str_shuffle($ForgotKeyString), 0, $ForgotKeyLength); //shuffle String, start with 0, 9 characters long

    $sql = "UPDATE UserTable SET ForgotKey = ".$ForgotKey." WHERE Email = ? ";
    $stmt = mysqli_stmt_init($conn);
    if (!mysqli_stmt_prepare($stmt, $sql)) {
        header("Location: ../forgot.php?error2"); // THE ERROR HAPPENS HERE, UNABLE TO PREP STATEMENT
        exit();
    }
    else {
        mysqli_stmt_bind_param($stmt, "s", $Email);
        mysqli_stmt_execute($stmt); // I believe this line should update the table

        $result = mysqli_stmt_get_result($stmt);
        if ($row = mysqli_fetch_assoc($result)) {
            //success: send user their email from here
            $variable = $row['Email'];
        }
        else {
            header("Location: ../forgot.php?error5");
            exit();
        }
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source