php - How To Track For Which Foreign Key To Add A Value To? (ex: Add The Data For The Correct User FK) -
i have no idea how phrase correctly, hope title not far off.
i know how add values table using php , passing values via sql. however, don't know how how ensure correct foreign key used particular entry.
i think it's best describe through example.
say have userbase table has usernameid(pk). have table called age , has column called age , usernameid(fk).
so i'm saying there usernameid foreign key in age table. now, when have form on website , asks age person , person logged in, how can ensure when add age of particular user, gets added correct usernameid(fk). i'm going make assumption usernameid ready created, juts need know how ensure data gets connected right fk.
does make sense saying? i've been searching google have no idea how describe want!
while creating table define foreign key constraint. eg.
create table age ( id int not null, age int not null, username varchar(10), primary key (id), foreign key (username) references user(username) );
here, user parent table username column primary key , in age table foreign key. if have used in db defining fk on php code auto show err if trying put other value allowed.
i hope help.
Comments
Post a Comment