Jump to content

PHP MYSQL FK


proctk

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]
Link to comment
https://forums.phpfreaks.com/topic/16043-php-mysql-fk/
Share on other sites

Archived

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

×
×
  • Create New...

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.