Problems with jQuery and javascipt when consulting

2

Good day I am developing an application in php, the problem is that when making the query I can not find the data that if it is hosted in the database, I am using jQuery and a function in javascript that redirects me to the consumption. This is my code.

    function consultarPaciente(){
        url = "index.php?accion=consultarPaciente&documento="+$("#asignarDocumento")
                .attr("value");
        $("#paciente").load(url);
    }


    <html>
        <head>
            <meta charset="UTF-8" content="text/html" http-equiv="Content-Type">
            <title>Sistema Gestion Odontologica</title>
            <link href="Vista/css/estilos.css" rel="stylesheet" type="text/css">
            <script type="text/javascript" src="Vista/jquery/jquery-3.3.1.min.js"></script> 
            <script type="text/javascript" src="Vista/js/script.js"></script>
        </head>
        <body>
            <div id="contenedor">
                <div id="encabezado">
                    <img src="Vista/imagenes/odontologia.png" width="100%" height="150px" >
                </div>
                <ul id="menu">
                    <li><a href="index.php">Inicio</a></li>
                    <li class="activa"><a href="index.php?accion=asignar">Asignar Cita</a></li>
                    <li><a href="index.php?accion=consultar">Consultar Cita</a></li>
                    <li><a href="index.php?accion=cancelar">Cancelar Cita</a></li>
                </ul>
                <div id="contenido">
                    <h2 style="width:100%">Asignar Cita</h2>
                    <form id="frmAsignar" method="POST" action="index.php?accion=guardarCita">
                        <table>
                            <tr>
                                <td>Documento del Paciente</td>
                                <td><input type="text" name="asignarDocumento" id="asignarDocumento"></td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                <input type="button" name="asignarConsultar" value="Consultar" id="asignarConsultar" onclick="consultarPaciente()">
                                </td>
                            </tr>

I have a driver class that handles the following format.

    public function consultarPaciente($doc) {
        $gestorCita = new GestorCita();
        $result = $gestorCita->consultarPaciente($doc);
        require_once 'Vista/html/consultarPaciente.php'; 
    }

the manager class is the following:

    # metodo consultar paciente
public function consultarPaciente($doc){
    $conexion = new Conexion();
    $conexion->abrir();

    $sql = "SELECT * FROM Pacientes WHERE pacIdentificacion = '$doc' ";

    $conexion->consultar($sql);
    $result = $conexion->obtenerResult();
    $conexion->cerrar();

    return $result;
}

and all this redirects me to consultPaciente.php:

    <?php
if($result->num_rows > 0){
?>
<table>
    <tr>
        <td>Identificacion</td>
        <td>Nombre</td>
        <td>Sexo</td>
    </tr>
    <?php
    $fila = $result->fetch_object();
    ?> 
    <tr>
        <td><?php echo $fila->pacIdentificacion ?></td>
        <td><?php echo $fila->pacNombres." ".$fila->pacApellidos; ?></td>
        <td><?php echo $fila->pacSexo; ?></td>  
    </tr>
</table>
<?php
}
else{
?>

     El Paciente no se encuentra en la base de datos.<br/>
    <input type="button" name="ingPaciente" value="Ingresar Paciente" id="ingPaciente" onclick="ingPaciente()">
<?php
}
?>

This is the main page index.php where I call all the actions of the system.

<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <?php
    require_once 'Controlador/Controlador.php';
    require_once 'Modelo/GestorCita.php';
    require_once 'Modelo/Cita.php';
    require_once 'Modelo/Paciente.php';
    require_once 'Modelo/Conexion.php';

    $controlador = new Controlador();

    if(isset($_GET['accion'])){

        if($_GET['accion'] == 'asignar'){
            $controlador->verPagina('Vista/html/asignar.php');
        }
        elseif($_GET['accion'] == 'consultar'){
            $controlador->verPagina('Vista/html/consultar.php');
        }
        elseif ($_GET['accion'] == 'cancelar') {
            $controlador->verPagina('Vista/html/cancelar.php');
        }
        elseif ($_GET['accion'] == 'guardarCita') {
           $controlador->agregarCita($_POST['asignarDocumento'], $_POST['medico'],
                   $_POST['fecha'], $_POST['hora'], $_POST['consultorio']); 
        }
        elseif($_GET['accion'] == 'consultarCita'){
            $controlador->consultarCitas($_POST['consultarDocumento']);
        }
        elseif ($_GET['accion'] == 'cancelarCita') {
            $controlador->cancelarCita($_POST['cancelarDocumento']);
        }
        elseif ($_GET['accion'] == 'consultarPaciente') {
            $controlador->consultarPaciente($_GET['documento']);
        }
        else{
            $controlador->verPagina('Vista/html/inicio.php');
        }
    }
    else{
        $controlador->verPagina('Vista/html/inicio.php');
    }

    ?>
</body>

the patient is in the database, but at the time of consulting I appear as NOT existing.

The problem that I detect is: . that the document for the consultation is not coming to me.

Thank you very much for your time and I hope you can help me, I am a novice in this.

    
asked by Jhon James Hernandez 25.11.2018 в 17:07
source

1 answer

0

You are not returning the value, because you can not find it, that is because the query is wrong, either you are not getting the value of the input or it is not happening, in your code you are not doing the checks or by tracking your information flow to verify if the value of the input is the one entered in your sql query, now assuming that the desired value reaches the sql query, when replacing the value your string takes as value to search for '$ doc ', not the value of the variable $ doc In your SQL query

$sql = "SELECT * FROM Pacientes WHERE pacIdentificacion = '$doc' ";

Replaces

$sql = "SELECT * FROM Pacientes WHERE pacIdentificacion = '".$doc."' ";
    
answered by 30.11.2018 в 05:05