function store_data_in_db()
{
    ### NOT A DUP
    process_parameters();
    validate_data($_POST);
    $db = get_db_handle();
    $params = $_POST;
    // insert parent info
    $parent_fname = $params['fname'];
    $parent_mname = $params['mname'];
    $parent_lname = $params['lname'];
    $parent_address = $params['address'];
    $parent_address1 = $params['address1'];
    $parent_hphone = $params['home_area_phone'] . $params['home_prefix_phone'] . $params['home_phone'];
    $parent_cphone = $params['cell_area_phone'] . $params['cell_prefix_phone'] . $params['cell_phone'];
    $parent_city = $params['city'];
    $parent_state = $params['state'];
    $parent_zip = $params['zip'];
    $parent_email = $params['email'];
    $sql = "INSERT INTO parent (first_name, middle_name, last_name, address1, address2, city, state, zip, primary_phone, secondary_phone, email)" . "VALUES('{$parent_fname}','{$parent_mname}','{$parent_lname}','{$parent_address}','{$parent_address1}','{$parent_city}', '{$parent_state}','{$parent_zip}', '{$parent_hphone}', '{$parent_cphone}', '{$parent_email}' );";
    mysqli_query($db, $sql);
    $how_many = mysqli_affected_rows($db);
    if ($how_many == 1) {
    } else {
        $msg = "A critical error occurred  in parent insertion. <br />";
        write_form_error_page($msg);
        exit;
    }
    //echo $sql;
    // insert child info
    $parent_id = 0;
    $parent_phone = $params['home_area_phone'] . $params['home_prefix_phone'] . $params['home_phone'];
    $sql = "SELECT id from `parent` where primary_phone='{$parent_phone}';";
    $result = mysqli_query($db, $sql);
    if (mysqli_num_rows($result) > 0) {
        $row = mysqli_fetch_array($result);
        $parent_id = $row[0];
    }
    $child_relation = $params['relation'];
    $child_fname = $params['cfname'];
    $child_lname = $params['clname'];
    $child_mname = $params['cmname'];
    $child_bday = $params['bday'];
    $child_gender = $params['gender'][0];
    $child_ifile = $params['cfname'] . "_" . $_FILES['fileUpload']['name'];
    $child_nickname = $params['goesby'];
    $child_conditions = $params['conditions'];
    $child_diet = $params['diet'];
    $child_emname = $params['emeContactname'];
    $child_emphone = $params['area_phone'] . $params['prefix_phone'] . $params['phone'];
    $sql = "INSERT INTO child(parent_id, relation, first_name, middle_name, last_name, nickname, image_filename, gender, birthdate, conditions, diet, emergency_name, emergency_phone) " . "VALUES ('{$parent_id}','{$child_relation}','{$child_fname}','{$child_mname}','{$child_lname}','{$child_nickname}','{$child_ifile}','{$child_gender}',STR_TO_DATE('{$child_bday}','%d/%m/%Y'),'{$child_conditions}','{$child_diet}','{$child_emname}','{$child_emphone}');";
    mysqli_query($db, $sql);
    $how_many = mysqli_affected_rows($db);
    if ($how_many == 1) {
    } else {
        $msg = "A critical error occurred  in child insertion. <br />";
        write_form_error_page($msg);
        exit;
    }
    // echo $sql;
    // insert enrollment
    $child_id = 0;
    $sql = "SELECT id from `child` where parent_id = '{$parent_id}' and first_name = '{$child_fname}'";
    $result = mysqli_query($db, $sql);
    if (mysqli_num_rows($result) > 0) {
        $row = mysqli_fetch_array($result);
        $child_id = $row[0];
    }
    $enrollment = 0;
    $program = $_POST['program'];
    for ($i = 0; $i < count($program); $i++) {
        $program_id = get_program_id($program[$i]);
        $sql = "INSERT INTO `enrollment`(`program_id`, `child_id`) VALUES ({$program_id}, {$child_id});";
        mysqli_query($db, $sql);
        $how_many = mysqli_affected_rows($db);
        //		echo $sql;
        if ($how_many == 1) {
        } else {
            $msg = "A critical error occurred  in enrollment insertion.";
            write_form_error_page($msg);
            exit;
        }
    }
    mysqli_close($db);
}
 * This page allows for the tagging of program objectives to course objectives.
 */
global $PAGE, $CFG, $DB, $USER;
require_once '../../config.php';
require_once 'lib.php';
// Check that they can access
require_login();
// TODO: Get permissions working
//require_capability('local/metadata:ins_view', $context);
require_once $CFG->dirroot . '/local/metadata/tag_form.php';
$categoryId = get_category_id();
$PAGE->set_category_by_id($categoryId);
$courseId = get_course_id();
$objectiveId = get_objective_id();
$groupId = get_group_id();
$programId = get_program_id();
$course = $DB->get_record('course', array('id' => $courseId), '*', MUST_EXIST);
// Set up page information
$PAGE->set_context(context_coursecat::instance($categoryId));
$PAGE->set_pagelayout('standard');
$PAGE->set_title(get_string('ins_pluginname', 'local_metadata'));
$heading = 'Program Learning Objectives: ' . $course->shortname . ': ' . $course->fullname;
$PAGE->set_heading($heading);
// Create url
$base_url = new moodle_url('/local/metadata/admview_tag.php', array('categoryid' => $categoryId, 'id' => $courseId, 'program' => $programId, 'obj' => $objectiveId, 'grp' => $groupId));
$knowledge_url = create_manage_url('knowledge', $categoryId);
$policy_url = create_manage_url('policy', $categoryId);
$tag_url = create_manage_url('course', $categoryId);
$exclude_url = create_manage_url('exclude', $categoryId);
$reporting_url = create_manage_url('reporting', $categoryId);
$categories_url = create_manage_url('categories', $categoryId);