Page 1 of 1
[SOLVED] What does this SQL error mean?
Posted: Fri Aug 13, 2010 12:00 am
by Bbob
Cannot add or update a child row: a foreign key constraint fails (`hp`.`materialinventory`, CONSTRAINT `materialinventory_ibfk_1` FOREIGN KEY (`vendorid`) REFERENCES `vendorinfo` (`vendorid`) ON DELETE CASCADE ON UPDATE CASCADE)
Does that mean that the "vendorid" from materialinventory cannot have duplicate values?
I used phpmyadmin from WAMP to set the vendorid from materialinventory as an index, then connected it to the "vendorid" of vendorinfo.
Did I set it correctly? I need to have duplicate vendorid from material inventory so I can connect different items to its vendor.
Here's my SQL query
INSERT INTO materialinventory VALUES('', '$type','$description','','$unit','$unitcost','','$id', '$date'
Re: What does this SQL error mean?
Posted: Fri Aug 13, 2010 3:35 am
by JakeJ
First of all, this makes no sense:
INSERT INTO materialinventory VALUES('', '$type','$description','','$unit','$unitcost','','$id', '$date'
How about: INSERT INTO materialinventory (field1, field2, etc.) VALUES ('$var1', '$var2', '$var3')
Secondly: If you're going to post code, please enclose it in the PHP Code tags. You can click the button for it in the formatting tool bar.
Thirdly, what your error means is that you're trying to change something that other things depend on and it would break it. SO you have to examine your query, find the dependencies, etc.
Look up some stuff on foreign keys, cascading and constraints.
Re: What does this SQL error mean?
Posted: Fri Aug 13, 2010 7:31 am
by Bbob
Hi thanks for the reply
JakeJ wrote:First of all, this makes no sense:
INSERT INTO materialinventory VALUES('', '$type','$description','','$unit','$unitcost','','$id', '$date'
How about: INSERT INTO materialinventory (field1, field2, etc.) VALUES ('$var1', '$var2', '$var3')
I got that from w3schools and its working.
Secondly: If you're going to post code, please enclose it in the PHP Code tags. You can click the button for it in the formatting tool bar.
Sorry, I thought the PHP Code tag was only for PHP Code. Ill use it the next time I add any other code.
Thirdly, what your error means is that you're trying to change something that other things depend on and it would break it. SO you have to examine your query, find the dependencies, etc.
I manage to fix there error by using a session. The vendorid from the material inventory wasnt getting any value so I used a session to pass the value to the other page.
Re: [SOLVED] What does this SQL error mean?
Posted: Fri Aug 13, 2010 7:36 am
by JakeJ
This query works?
VALUES('', '$type','$description','','$unit','$unitcost','','$id', '$date'
A quote mark as a value and no closing parenthesis?
OHHHHH... just as I was typing that, i realized it's probably two single quotes and you just didn't paste in the ).
And sessions are great for passing data. Pretty much indispensable.
I'm glad you got your problem solved.