Jump to content

Archived

This topic is now archived and is closed to further replies.

proctk

PHP MYSQL FK

Recommended Posts

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=php:0]

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]

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

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



?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.