Assuming that your tables are structured something like:
users:
user_id integer
user_name varchar(50)
user_other_data varchar(999)
primary key (user_id)
unique (user_name)
other_table:
user_value varchar(999)
user_id integer foreign key (users.user_id)
What you want is the ability to insert an entry into other_table
given only the value and the user name.
It's important that you do this in an atomic way to ensure the user_id/user_name mapping isn't changed underneath you. In other words, you can't do:
get user_id from users based on user_name.
insert value and user_id into other_table.
since the user_id or user_name may change between those two steps above (the user_id probably wouldn't change for the physical row, but it's certainly possible that the table could change from:
user_id user_name
------- ---------
1 bob
2 george
to:
user_id user_name
------- ---------
1 george
2 bob
So, to do it atomically, it has to be in a single SQL statement (or part of a transaction but you can avoid a transaction in this case):
insert into other_table (user_value, user_id)
select :value, user_id from users where user_name = :name;
For your specific case (added after my original answer), you're looking at:
insert into AvatarTable (UserID,AvatarURL)
select UserID, :localAvatarURL
from UserTable
where UserName = :localUserName;