+ 1

[ERROR SQL] I need help fixing this error

when i try to run this: $queryMenu = "SELECT `user_menu`.`id`, `menu` FROM `user_menu` JOIN `user_access_menu` ON `user_menu`.`id` = `user_access_menu`.`menu_id` WHERE `user_access_menu`.`role_id` = $role_id ORDER BY `user_access_menu`.`menu_id` ASC "; I got the Error Number: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ORDER BY `user_access_menu`.`menu_id` ASC' at line 5. Thank you. #I've already tried to add ';' after 'ASC' but still got the same error

20th Mar 2019, 8:47 AM
Himas Adin Nugroho
Himas Adin Nugroho - avatar
2 Antworten
+ 2
I don;t have knowledge about Maria DB. But I would try something like : If role_id is number --- $queryMenu = "SELECT user_menu.id , menu FROM user_menu JOIN user_access_menu ON user_menu.id = user_access_menu.menu_id WHERE user_access_menu.role_id = ".$role_id." ORDER BY product_manufacturer DESC"; or If role_id is string --- $queryMenu = "SELECT user_menu.id , menu FROM user_menu JOIN user_access_menu ON user_menu.id = user_access_menu.menu_id WHERE user_access_menu.role_id = '".$role_id."' ORDER BY product_manufacturer DESC"; --======================= Print also the variable to check what is the string which is constructed to check if it is valid
20th Mar 2019, 9:14 AM
Prokopios Poulimenos
Prokopios Poulimenos - avatar
0
$role_id = $this->session->userdata('role_id');
20th Mar 2019, 9:31 AM
Himas Adin Nugroho
Himas Adin Nugroho - avatar