Jump to content


Photo

PHP MYSQL FK


  • Please log in to reply
No replies to this topic

#1 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 30 July 2006 - 08:25 PM

Hi

My database has five tables four of which I have linked to master table with a FK. the linking column is the PK. My question when data is entered is the mastertable suposed to update the link column automaticly.

I included some code I used to create my tables to give an idea what I'm trying to do.




code to create the table

include 'db.php'; 

mysql_query("CREATE TABLE children (
  child_id int(25) NOT NULL auto_increment,
  childfirstname varchar(25) NOT NULL default '',
  childlastname varchar(25) NOT NULL default '',
  childdob varchar (25) default '',
  childsex varchar (25) default '',
  CONSTRAINT child_pk PRIMARY KEY (child_id)
  
)")or die("Create table Error: ".mysql_error());


?> 

code I used to upate the tables ( with editing to names)

mysql_query("ALTER TABLE master
add CONSTRAINT fk_users
  FOREIGN KEY (user_id)
  REFERENCES users(users_id);
") or die("Create table Error: ".mysql_error());



?> 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users