<?php

include "valida.php";
define('AT_INCLUDE_PATH', 'include/');
include_once AT_INCLUDE_PATH . 'funciones_bd.php';
if (!isset($_POST['nombres']) || !isset($_POST['apellidos'])) {
    header("location: ingresarstudents.php?error=1");
} elseif ($_POST["nombres"] == "" || $_POST["apellidos"] == "") {
    header("location: ingresarstudents.php?error=2");
} else {
    $data_conn = new funciones_BD();
    //se hace la insercion del estudiante en la tabla students y se recupera el codigo asignado:
    if ($data_conn->insert_student($_POST["nombres"], $_POST["apellidos"])) {
        $codig = $data_conn->getLastStudentCode();
        $row = mysql_fetch_row($codig);
        //echo "<br><p>cod: ".$row[0]."</p>";
        //print_r($codig);
        //se retorna la confirmacion y el codigo de estudiante que se ha insertado:
        header("location: ingresarstudents.php?conf=1&cod=" . $row[0]);
    } else {
        header("location: ingresarstudents.php?error=3");
    }
}