Jump to content

hi there


FURQAN

Recommended Posts

hi there

there is a problem in my code that i am having two tables and i have made a foreign key the code that show it is as follows

 

<?php
mysql_connect('localhost','root','') or die('cannot connect');
mysql_select_db('normalisation') or die('cannot connect');

$sql="CREATE TABLE parent (id INT(25) NOT NULL,
                     PRIMARY KEY (id)
) ENGINE=INNODB";
$sql1="CREATE TABLE child (id INT(25) NOT NULL, parent_id INT(25) NOT NULL,
                    INDEX par_ind (parent_id),
                    FOREIGN KEY (parent_id) REFERENCES parent(id)
                      ON DELETE CASCADE  ON UPDATE CASCADE
) ENGINE=INNODB";

mysql_query($sql);
mysql_query($sql1) or die('cannot run');

?>

 

 

 

actually i am using on delete cascade and on update cascade which means that if i update or delete in one table then the other table in which there is a foreign key will be deleted and updates simultaneously

 

 

but the thing is that when i am inserting the data in "parent" table the data is not getting inserted in the child table

 

 

can somebody help me

is shall be very thankfull to you

Link to comment
https://forums.phpfreaks.com/topic/204674-hi-there/
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.