Kees deVries wrote:This is the errror code :Cannot add or update a child row: a foreign key constraint fails (`orderapp`.`orderproducts`, CONSTRAINT `FK_orderID` FOREIGN KEY (`order_ID`) REFERENCES `orders` (`orderID`) ON DELETE NO ACTION ON UPDATE NO ACTION)
So for some reason you are violating this constraint. Which values are you trying to insert? And what's the content of the
orders table?
A few other remarks regaringd your code:
1/ (as Brian already mentioned)
you should consider using prepared statements in order to prevent possible SQL injection attacks (and enjoy other benefits as well). More info about prepared statements can be found
here.
2/ in the
update method you are not closing the
Statement resource. It's always a good practice to close your resources once they are not needed anymore.
Hope it helps!
Kind regards,
Roel