CasperSecurity
<?php
session_start();
include '../../../../web/connection/connection.php';
//canteen menu variables
$canteen_id = $_REQUEST['canteen_id'];
$effective_date = $_REQUEST['effective_date'];
$food_type = $_REQUEST['food_type'];
$meant_for = $_REQUEST['meant_for'];
$menu_day = $_REQUEST['menu_day'];
$created_on = date("Y-m-d");
$created_by = $_SESSION['USER_ID'];
$is_active = 'yes';
//canteen menu item variables
$food_item_id = $_REQUEST['food_item_id'];
//inserting data into canteen menu table
$db_handle = new DBController();
$newInsert = $db_handle->tableinsert("INSERT INTO canteen_menu (canteen_id,effective_date,food_type,meant_for,menu_day,created_on,created_by,is_active)
VALUES ('$canteen_id','$effective_date','$food_type','$meant_for','$menu_day','$created_on','$created_by','$$is_active')");
if($newInsert == TRUE){
echo 'Data Inserted in table 1 Successfully';
//if insertion is successful in canteen menu table then fetch a particular primary key needed
$db_handle = new DBController();
$select = $db_handle->runQuery("SELECT canteen_menu_id FROM canteen_menu WHERE effective_date = '$effective_date' ");
foreach ($select as $v){
$canteen_menu_id = $v['canteen_menu_id']; // unique primary key needed as a data for the nested table
}
echo $canteen_menu_id ;
//inserting canteen menu item's ingredients into their own table only if there is a succesful insertion in canteen menu table so that we can fetch its unique key that will be insert in this table
$db_handle = new DBController();
$newInsert2 = $db_handle->tableinsert("INSERT INTO canteen_menu_item (canteen_menu_id,food_item_id)
VALUES ('$canteen_menu_id','$food_item_id')");
if($newInsert2 == TRUE){
echo 'Data Inserted in table 2 Successfully';
}else{
echo 'Not Inserted 2' ;
}
}else{
echo 'Not Inserted 1' ;
}
?>