View Single Post
Old 12-19-2012, 08:43 PM   PM User | #7
chkakashi24
New to the CF scene

 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
chkakashi24 is an unknown quantity at this point
Quote:
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:
PHP Code:
Code:
DROP TABLE IF EXISTS `accounts`;
CREATE TABLE `accounts` ( 
`
accidint(4NOT NULL AUTO_INCREMENT
`
accnovarchar(10NOT NULL
`
balanceint(11NOT NULL
`
typevarchar(100NOT NULL
`
activevarchar(5NOT NULL
`
cusidINT REFERENCES customer(cusid),
PRIMARY KEY (`accid`) 
ENGINE=InnoDB
And then you could remove accid from the customer table.

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

PHP Code:
$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')"

Last edited by chkakashi24; 12-19-2012 at 08:52 PM..
chkakashi24 is offline   Reply With Quote