Say I have two tables, ‘users’ and ‘restaurants’.
Users Table:
user_id | u_name | |
---|---|---|
1 | [email protected] | John |
2 | [email protected] | Jane |
Restaurants table –
here owner
is the foreign key referencing user_id
restaurant_id | r_name | address | owner |
---|---|---|---|
1 | KFC | New York | 1 |
2 | Starbucks | Texas | 2 |
i have a form where the user enter details into the first table. And then i have another form to enter details into second table. how do i set the values in ‘owner’ column? The user_id and restaurant_id are auto generated. How do i know which restaurant belongs to which user?
2
Answers
You can use a SELECT statement in your INSERT, like this:
In the second form(form to enter details into second table),
a dropdown can be provided which displays list of users from table 1. dropdown usually has value and text part. value can be set to user_id and text can be set to u_name / email.
r_name and address, you are getting from user in the second form?