Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.