I have a table (users) that looks like this:
ID | CODE | Name
---+----------+---------
1 | 00A | Tom
2 | 12E | Steve
3 | A4B | Maria
Now I have other table to insert data, and I need to insert user_id
. The thing is I receive only the user code from a document.
I have to search in the users table the id that corresponds to that code.
I imagine I have to do something like this:
$code = 123
$query="select from users where id=$code"
$user_id = $query
$sql = "insert into table values ($user_id)"
I know the SQL/PHP code is not complete, I'm just looking for the correct LOGIC to this. Maybe there's a way to search and insert at the same query.