skip to Main Content

I have two table in my database first is shop_details and second one is shopOwner_login

in shop_details table there is column named

ShopOwner_email
Shop_Pass 

and same in shopOwner_login table there is

ShopOwner_Id,
ShopOwner_email,
Shop_Pass

Now i want to make a form in which if user enter data in shop details table like shopowner Email and its password it will store on those two table automatically goes

Can i do this if yes please help me for it i also tried foreign key i am so confused with foreign key because i am new to php and MySql please help me.

2

Answers


  1. Each of your table should have Primary key. Primary Key is the unique id (could be number or string or even uuid. Ex: ShopOwner_Id) which could be used to fetch any row in the table. This primary key is used to establish relationships between tables.

    Also for relationships there could be 3 types of major relationships between two tables.

    • One to One
    • One to Many or Many to One
    • Many to Many

    For example,

    1. lets say you have two tables UserLogin and UserProfile. UserLogin contains -> id, email, password, and verified. Whereas UserProfile contains -> id name, address, mobile, dob, etc. Here Each UserLogin will have single UserProfile whereas each UserProfile will have only one UserLogin. So they have One to One relationship. In this case, You add the foreign key to the both tables. You will add profile_id as foreign key in UserLogin whereas login_id in UserProfile.

    2. Lets say, you have two tables Shop and User. Where each Shop will belong to a single User (in your case shopowner) But a User can have multiple Shops. In this case, Shop and User have Many to One relationship (or User and Shop have One to Many relationship). In this case we add a foreign key of user_id (which is primary key of User table) to Shop table.

    In your case I will suggest to only keep email and password in shopOwner_login table and add its foreign key to shop_details table. This way your data will be normalize and you will not have to make sure to maintain same data in multiple tables.

    Login or Signup to reply.
  2. So,d query need to fetch the data looks like – SELECT a.ShopOwner_email Shop_Pass as EmailId,a.Shop_Pass as Password FROM shop_details as a left join shopOwner_login as b on b.ShopOwner_Id = a.ShopOwner_Id

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search