尝试将其插入数据库时​​,无法识别我的用户ID会话cookie

I have a customer details form I am trying to insert into my Customer table. The insertion isn't working, but I've identified that it's the session cookie at fault, by changing the $user_ID to a '1' and then it successfully inserted into the database. I'd really appreciate help in identifying where I've gone wrong with setting or calling my session cookie, or what I should do to get it to work. Thanks.

Setting the session cookie on login:

$sql = "SELECT User_ID, Username, Password, User_Level
        FROM Account
        WHERE Username = '$username' AND  Password = '$password'";

    $record = mysql_query($sql);

    $row = mysql_fetch_array($record);

if(mysql_num_rows($record) == 0){
    die(header("location: LoginFailed.html"));


}else if(mysql_num_rows($record) == 1){
    $row = mysql_fetch_array($record);
    $_SESSION["User_ID"] = $row["User_ID"];
    $_SESSION["User_Level"] = $row["User_Level"];
    header("location:Home.html");

}
    else{$row = mysql_fetch_array($record);

    $_SESSION["User_ID"] = $row["User_ID"];
    $_SESSION["User_Level"] = $row["User_Level"]; 
    header("location: Home.html");
}

mysql_close();

Assigning the session cookie to a variable in php:

session_start();
$user_ID = $_SESSION['User_ID'];

The insertion code used:

    INSERT INTO Customer (User_ID, Forename, Surname, Address1, Address2, Town, Country, Postcode, Phone_No, Mobile, dob, Emergency_Name, Emergency_Number, Nationality, Profession, Academic_Qual, Volunteer_Reason) 
VALUES ('$user_ID', '$regForename', '$regSurname', '$regAddress1', '$regAddress2', '$regTown', '$regCountry', '$regPostcode', '$regPhone', '$regMobile', '$regDOB', '$regEmergencyName', '$regEmergencyPhone', '$regNationality', '$regProfession', '$regQualification', '$regVolunteer')";

I tried an echo of the sql code and the User_ID is blank so it is failing to obtain it, at all. Really appreciate your help.

according your description,When ‘echo’ SQL , the User_ID is blank, you need check the variable $user_ID has value , and should also check table Customer field Use_ID‘s type , it’s int or varchar ? it can be null ? it's unique ? If you do not know what i say, you can post your table structure.