CasperSecurity
<?php
session_start();
include '../../../../web/connection/connection.php';
//daily stock indent variables
$indent_date = $_REQUEST['indent_date'];
$canteen_indent_no = $_REQUEST['canteen_indent_no'];
$canteen_id = $_REQUEST['canteen_id'];
$meant_for = $_REQUEST['meant_for'];
$no_person = $_REQUEST['no_person'];
$indent_status = $_REQUEST['indent_status'];
$created_on = date("Y-m-d");
$created_by = $_SESSION['USER_ID'];
$is_active = 'yes';
//daily stock indent item variable
$item_id = $_REQUEST['item_id'];
$item_quantity = $_REQUEST['item_quantity'];
$item_status = $_REQUEST['item_status'];
//inserting data into daily stock indent table
$db_handle = new DBController();
$newInsert = $db_handle->tableinsert("INSERT INTO daily_stock_indent(indent_date,canteen_indent_no,canteen_id,meant_for,no_person,indent_status,created_on,created_by,is_active)
VALUES ('$indent_date','$canteen_indent_no','$canteen_id','$meant_for','$no_person','$indent_status','$created_on','$created_by','$is_active')");
if($newInsert == TRUE){
echo 'Data Inserted in table 1 Successfully';
//if insertion is successful in daily stock indent table then fetch a particular primary key needed
$db_handle = new DBController();
$select = $db_handle->runQuery("SELECT daily_stock_indent_id FROM daily_stock_indent WHERE canteen_id = '$canteen_id' ");
foreach ($select as $v){
$daily_stock_indent_id = $v['daily_stock_indent_id']; // unique primary key needed as a data for the nested table
}
//inserting daily stock indent food item's ingredients into their own table only if there is a succesful insertion in daily stock indent 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 daily_stock_indent_item(daily_stock_indent_id,item_id,item_quantity,item_status)
VALUES ('$daily_stock_indent_id','$item_id','$item_quantity','$item_status')");
if($newInsert2 == TRUE){
echo 'Data Inserted in table 2 Successfully';
}else{
echo 'Not Inserted 2' ;
}
}else{
echo 'Not Inserted 1' ;
}
?>