Hi,
i am trying to INSERT into a table lets say 4 values:
- value1
- value2
- value3
- value4
all these values are stored in variables($var1 , $var2, $var3..), except one of them which is part of the final value ($var4).
$var4 may return the final value4 only if with a query to another table.
$var4 stores the name of a user.
and but I want to INSERT not the user_name, but the user_id.
"user_id" is in Table "users" and i can obtain it by doing :
but the insertion i want to do is into another table. so i would want to do for my final query:
could this work?
should i specify in the INSERT that the cols pertain to some_table like:
or am i totally wrong?
or should i first run the query to get the user_id and then make another one to INSERT?
thankyou
bilibytes
i am trying to INSERT into a table lets say 4 values:
- value1
- value2
- value3
- value4
all these values are stored in variables($var1 , $var2, $var3..), except one of them which is part of the final value ($var4).
$var4 may return the final value4 only if with a query to another table.
$var4 stores the name of a user.
and but I want to INSERT not the user_name, but the user_id.
"user_id" is in Table "users" and i can obtain it by doing :
Code:
SELECT user_id FROM users WERE user_name = $var4
Code:
INSERT INTO some_table (var1_col, var2_col, var3_col, user_id) VALUES ($var1, $var2, $var3, ([INDENT]SELECT users.user_id FROM users WHERE users.user_name = $var4 ) [/INDENT] )
should i specify in the INSERT that the cols pertain to some_table like:
Code:
INSERT INTO some_table (some_table.var1_col, some_table.var2_col, some_table.var3_col, some_table.user_id) VALUES ($var1, $var2, $var3, ([INDENT]SELECT users.user_id FROM users WHERE users.user_name = $var4 ) [/INDENT] )
or should i first run the query to get the user_id and then make another one to INSERT?
thankyou
bilibytes
Comment