dubfoundry Posted December 12, 2008 Share Posted December 12, 2008 Im currently building an app where user can customize an item upload a photo register and login to an account...so far all those scripts work great.. Now i need to have all the cust info pulled from multiple tables using an id reference so it can be displayed on the member area page. (whats the php/mysql script for this by the way?) They are 3 tables in the database user,products and prd_order... in the user table there is a id(primaryKey) field and the prd_order table have an userid(set as an index) field in it.... I need both to be linked so that a new user auto links to his product choice in the prd_order table. So i converted both tables to InnoDB and attempted to link both via the relational view panel i got this error-- Error SQL query: ALTER TABLE `prd_order` ADD FOREIGN KEY ( `user_id` ) REFERENCES `imagecon`.`user` ( `id` ) MySQL said: Documentation #1216 - Cannot add or update a child row: a foreign key constraint fails so im stuck..whats the work around.... Is it possible to reffer to and link both fields with out a foreign key. can you pull from multiple tables without using a foreign key? Quote Link to comment Share on other sites More sharing options...
Twister1004 Posted December 12, 2008 Share Posted December 12, 2008 From my opinon, try taking out the "FOREIGN KEY" part. ALTER TABLE `prd_order` ADD ( `user_id` ) REFERENCES `imagecon`.`user` ( `id` ) I believe that will work. But I don't know. Quote Link to comment Share on other sites More sharing options...
dubfoundry Posted December 12, 2008 Author Share Posted December 12, 2008 ok but thats actually auto generated by php admin. Thanks for trying though.. anyone else some one who is familiar with this kind of stuff. Quote Link to comment Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 ALTER TABLE prd_order ADD FOREIGN KEY (user_id) REFERENCES user(id) Try writting it like that, yours looked fine, but I know this syntax is correct Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 12, 2008 Share Posted December 12, 2008 In MySQL you don't have to declare explicit foreign keys (BTW: Only InnoDB tables support those). To pull data from several related tables, just use JOINs in your queries. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.