Now, if you WANT to create the customer record first, then yes, it would make more sense to turn things around.
Add the cusid field to the accounts table and then change your constraint to go the other way.
Like this, maybe:
And then you could remove accid from the customer table.
DROP TABLE IF EXISTS `accounts`;
CREATE TABLE `accounts` (
`accid` int(4) NOT NULL AUTO_INCREMENT,
`accno` varchar(10) NOT NULL,
`balance` int(11) NOT NULL,
`type` varchar(100) NOT NULL,
`active` varchar(5) NOT NULL,
`cusid` INT REFERENCES customer(cusid),
PRIMARY KEY (`accid`)
As I said, either way works. Just don't try to go both ways.
i have this same problem when inserting >_<
I already checked my foreign keys and there seems to be nothing wrong with them @_@ PLEASE HELP?
And This is how my insert goes...
$pkey = mysql_insert_id();
$sql_query = "insert into med_rec(med_name, med_type) values ('$name', '$type')";
$sql_query2 = "insert into medicine(med_rec_ID, expiry) values (". $pkey .",'$exp')";
$sql_query3 = "insert into inventory(staff_ID, med_ID, qty) values (".$_SESSION['id'].",". $pkey .", '$qty')";