You would maybe like to use a transaction since you are setting the user id below?