PHP and MYSQL: Inserting Foreign Key
Get the solution ↓↓↓Solution:
In addition, you can also look up foreign keys on the fly by inserting the result of a lookup, e.g. to lookup the Foreign Key for 'Category 1' and then insert a new image referencing this category:
INSERT INTO Images(imgId, imgname, categoryFk)
SELECT 9876, 'photo1.jpg', cat.categoryId
FROM Category cat
WHERE cat.categoryName = 'Category 1';
Answer
Solution:
Not sure I understand you correctly, but from what I understand, this should do it:
INSERT INTO images
(imgid, imgname, categoryfk)
VALUES
('$x', '$category1', 1),
('$x', '$category2', 2),
('$x', '$allimages', 3)
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: deprecated: directive 'allow_url_include' is deprecated in unknown on line 0
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.