I have 4 pages, across which I need to share the same restaurant_ID. I need to be able to insert the ID into all 4 tables in the database.
I am using a INSERT INTO SELECT
statement to do so. But I am receiving the following error:
POSSIBLE Syntax Error (check preceding valid syntax error) unexpected: identifier 'SELECT'
POSSIBLE Syntax Error (check preceding valid syntax error) unexpected: identifier 'Resturant_ID'
POSSIBLE Syntax Error (check preceding valid syntax error) unexpected: identifier 'Rest_Dets'
This is the sql I am using:
(Original):
INSERT INTO Product (Resturant_ID)
SELECT Resturant_ID Rest_Dets;
(Edited):
INSERT INTO Product (Resturant_ID)
SELECT Resturant_ID FROM Rest_Dets;
I have also tried
$rest_id = mysqli_real_escape_string($dbc, $_SESSION['Resturant_ID']);
INSERT INTO Product (Resturant_ID)
SELECT Resturant_ID FROM Rest_Dets WHERE Resturant_ID = $rest_id ;
I have looked all over the internet and it doesn't seem like I should have a problem, the webpage is also connected successfully.
Rest_Details(The table i want to get the Restaurant_ID from)
CREATE TABLE `Rest_Details` (
`Resturant_ID` bigint(255) NOT NULL AUTO_INCREMENT,
`Resturant_name` varchar(100) NOT NULL,
`Resturant_des` varchar(200) NOT NULL,
`Res_Address_Line_1` varchar(200) NOT NULL,
`Res_Address_Line_2` varchar(200) DEFAULT NULL,
`City_name` varchar(100) NOT NULL,
`Resturant_Postcode` varchar(8) DEFAULT NULL,
`Cat_ID` tinyint(11) NOT NULL,
`Avg_Del` tinyint(11) NOT NULL,
`Est_Del` tinyint(11) NOT NULL,
`Email1` varchar(200) NOT NULL,
`Email2` varchar(200) DEFAULT NULL,
`Min_ord` tinyint(11) NOT NULL,
PRIMARY KEY (`Resturant_ID`),
UNIQUE KEY `Resturant_name` (`Resturant_name`),
UNIQUE KEY `Resturant_ID` (`Resturant_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
Products
CREATE TABLE `Product` (
`Product_Id` bigint(255) NOT NULL AUTO_INCREMENT,
`Resturant_ID` bigint(255) NOT NULL,
`Product_Name` varchar(100) NOT NULL,
`Product_Desc` text NOT NULL,
`Product_Price` decimal(65,0) NOT NULL,
`Add_On_ID` int(11) NOT NULL,
PRIMARY KEY (`Product_Id`),
UNIQUE KEY `Product_Id` (`Product_Id`),
UNIQUE KEY `Resturant_ID` (`Resturant_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8