I can run the following query in PHPMyAdmin, but for some reason I get a syntax error when I run it in a mysql method in PHP:
INSERT INTO product (model, stock_status_id, image, price, date_available, status, date_added, date_modified)
VALUES('SP44152', 5, 'data/products/SP44152-1.jpg', '18.04', '2012-06-18', 1, '2012-06-19 00:31:35', '2012-06-19 00:57:01');
SET @lastid = LAST_INSERT_ID();
INSERT INTO product_description (product_id, language_id, name, Description)
VALUES(@lastid, 1, 'Product item 1', 'Product Description');
INSERT INTO product_reward (product_id, customer_group_id, points)
VALUES(@lastid, 1, 0);
INSERT INTO product_to_category (product_id, category_id)
VALUES(@lastid, 67);
INSERT INTO product_to_store (product_id, store_id) VALUES(@lastid, 0);
the error code I am getting:
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @lastid = LAST_INSERT_ID(); INSERT INTO product_description (product_i' at line 3
I have tried removing the ; from the end of each line and I tried removing the field ‘status’ as I know that is also something you can use in MYSQL. There doesn’t seem to be much on the Internet that can help identify the cause on this one.
Any feedback is very welcome.
mysql_querydoes not like multiple, semi-colon separated statements:Break down your query into multiple queries and execute them one-by-one:
PS: I suggest that you look at alternatives to
mysql_*functions.