CasperSecurity
<?php
session_start();
include '../../../../web/connection/connection.php';
//add new branch variables
$branch_name = $_REQUEST['branch_name'];
$branch_short_name = $_REQUEST['branch_short_name'];
$no_seat = $_REQUEST['no_seat'];
$no_section = $_REQUEST['no_section'];
$branch_code = $_REQUEST['branch_code'];
$created_on = date('Y-m-d');
$created_by = $_SESSION['USER_ID'];
$is_active = 'yes';
//add new branch section variables
$academic_session = $_REQUEST['academic_session'];
$section_id = $_REQUEST['section_id'];
$capacity = $_REQUEST['capacity'];
//inserting data into branches table
$db_handle = new DBController();
$newInsert = $db_handle->tableinsert("INSERT INTO branchs(branch_name,branch_short_name,no_seat,no_section,branch_code,created_on,created_by,is_active)
VALUES('$branch_name','$branch_short_name','$no_seat','$no_section','$branch_code','$created_on','$created_by','$is_active')");
if($newInsert == TRUE){
echo 'Data Inserted into table 1 Successfully';
//if insertion is successful in branches table then fetch a particular primary key needed
$db_handle = new DBController();
$select = $db_handle->runQuery("SELECT branch_id FROM branchs WHERE branch_name = '$branch_name' ");
foreach ($select as $v){
$branch_id = $v['branch_id']; // unique primary key needed as a data for the nested table
}
// inserting data into branches section table
$db_handle = new DBController();
$newInsert2 = $db_handle->tableinsert("INSERT INTO branch_section(academic_session,branch_id,section_id,capacity)
VALUES( '$academic_session','$branch_id','$section_id','$capacity')");
if($newInsert2 == TRUE){
echo 'Data Inserted Successfully in table 2';
}else{
echo 'Not Inserted 2' ;
}
}else{
echo 'Not Inserted 1' ;
}
?>