<?php
session_start();
include '../admin/includes/database.php';
include '../admin/includes/functions.php';
$conn= new Functions();

if(!empty($_POST['psychomotor_name']) && !empty($_POST['psychomotor_value'])
    && !empty($_POST['id'])){
    $psychomotor_name = $_POST['psychomotor_name'];
    $psychomotor_value = $_POST['psychomotor_value'];
    $id = $_POST['id'];

    //check if details already exists

    $sql = "SELECT * FROM students_cognitive_area WHERE cognitive_name=:name AND cognitive_value =:value AND id =:id";
    $conn->query($sql);
    $conn->bind(':name', $psychomotor_name);
    $conn->bind(':value', $psychomotor_value);
    $conn->bind(':id', $id);


    $rowCount = $conn->rowCount();

    if($rowCount > 0){

        echo "<script>
            toastr['error']('Cognitive area Details already exists');
      </script>";
        return false;

    }else{
        //process  updating  of data into database

        $sql = "UPDATE students_cognitive_area SET cognitive_name=:name, cognitive_value =:value WHERE id =:id";
        $conn->query($sql);
        $conn->bind(':name', $psychomotor_name);
        $conn->bind(':value', $psychomotor_value);
        $conn->bind(':id', $id);


        $send = $conn->execute();
        if ($send) {

            echo "<script>
            toastr['success']('Cognitive area Details Updated Successfully.');
          </script>";

        } else {
            echo "<script>
            toastr['error']('An error occurred while updating details.');
          </script>";
        }


    }


}else{
    echo "<script>
            toastr['error']('Cognitive area name and value fields are required.');
      </script>";
}



