Lost data when saving in relational database

0

I've had this problem since I linked my database, at first I thought it was the error it was because all the data was not sent, but then try another DB without relating it and it turns out that if all the data are sent data and all the data coincide in their types ...

Here is a small example of the code, here comes the information and the data is sent to the functions to insert the data.

  $m_nombre = (string) $_POST['m_nombre'];
  $m_apellido = (string) $_POST['m_apellido'];
  $m_edad = $_POST['m_edad'];
  $m_sexo = $_POST['m_sexo'];
  $m_cedula = (integer) $_POST['m_cedula'];
  $clave = $_POST['clave'];
  $m_especialidad = (string) $_POST['m_especialidad'];
  try {
    $consultas = new Consultas();
    $consultas->getDoctor($m_nombre,$m_apellido,$m_edad,$m_sexo,$m_cedula,$clave);
    $consultas->getEspecialidad($m_especialidad);
    echo 'hecho.-->Procesar--Medico. <br>';
    //header("location:?accion=NuevoMedico");
    } catch (Exception $e) {
      echo 'try doctores... Se ha Presentado un Error. <pre><strong>' . $e->getMessage() . '</pre></strong>';
    }

These code blocks are for getting the data and then inserting it.

function getDoctor($m_nombre,$m_apellido,$m_edad,$m_sexo,$m_cedula,$clave){
        $conexion = new Conexion();
        $sql = "INSERT INTO doctores
        (nombre,apellido,edad,sexo,cedula,clave)
        VALUES
        (:nombre,:apellido,:edad,:sexo,:cedula,:clave)";

        $declaracion = $conexion->conn->prepare($sql);
        $declaracion->bindParam(':nombre',$m_nombre);
        $declaracion->bindParam(':apellido',$m_apellido);
        $declaracion->bindParam(':edad',$m_edad);
        $declaracion->bindParam(':sexo',$m_sexo);
        $declaracion->bindParam(':cedula',$m_cedula);
        $declaracion->bindParam(':clave',$clave);
        if (is_null($declaracion) and !isset($declaracion)) {
            echo 'error';
        }else{
            try {
            $declaracion->execute();
            echo 'hecho.-->getDoctor <br>';
            //header("location:?accion=home");                  
            } catch (Exception $e) {
                echo 'Se ha Presentado un Error. <pre><strong>' . $e->getMessage() . '</pre></strong>';
            }
        }
    }
function getEspecialidad($m_especialidad){
    $conexion = new Conexion();
    $sql = "INSERT INTO especialidades (especialidad) VALUES (:especialidad)";
    $declaracion = $conexion->conn->prepare($sql);
    $declaracion->bindParam(':especialidad',$m_especialidad);
    if (is_null($declaracion) and !isset($declaracion)) {
        echo 'error';
    }else{
        try {
        $declaracion->execute();
        echo 'hecho.-->getEspecialidad <br>';
        //header("location:?accion=home");                  
        } catch (Exception $e) {
            echo 'Se ha Presentado un Error. <pre><strong>' . $e->getMessage() . '</pre></strong>';
        }
    }
}

then this is what happens, it shows that all the data has been sent correctly but only the getEspecialidad is sent while all the doctor fields remain empty ...

This is how the database and its relationships look.

If you orient me a little or point out an error because I really can not see it, I would appreciate it very much, if it is necessary to show the rest of the DB and your relations indicate it to me along with any other doubt, thanks in advance.

    
asked by BlacDrak 03.03.2018 в 19:26
source

0 answers