Good day I have the following problem:
I make a query with a patient that is in the database, but I get that it does not exist in this.
I'm using jQuery I use a function that directs to another page and passes a variable 'document' to be processed on another page, the function is as follows:
function consultarPaciente(){
url = "index.php?accion=consultarPaciente&documento="+$("#asignarDocumento").attr('value');
$("#paciente").load(url);
//alert($("#asignarDocumento").attr('value'));
}
The line I have commented is to see if the variable of the identifier is reaching me, which generates me in the execution as undefined.
The page that uses the previous code is the following:
<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>
As you can see in the input where I receive the patient's document it is called assignDocument that is received in the javascript function before named consult Patient ().
The function directs me to the main page called index.php which receives what action is being taken and assigns the received variable and sends it to another function to be processed, the code of the index page is as follows.
<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>
Here we can see that instancio a class controller that is the one that executes the action that I want to do in this case is to consult Patient, now let's see the code of the function of said controller class:
#metodo consultar paciente
public function consultarPaciente($doc) {
$gestorCita = new GestorCita();
$result = $gestorCita->consultarPaciente($doc);
require_once 'Vista/html/consultarPaciente.php';
}
This code uses a GestorCita class and we use a specific method for the patient's search, let's see the function in the GestorCita class:
# 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;
}
This method returns a $ result that would be the number of rows in the query, let's see the code to consultPaciente that takes the $ result and saves it in a variable and directs to the page consultarPacinete.php let's see the page:
<?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; ?>
El Paciente no se encuentra en la base de datos.<br/>
<input type="button" name="ingPaciente" value="Ingresar Paciente" id="ingPaciente" onclick="ingPaciente()">
As we can see, this page takes the $ result variable from the method that was used and shows the patient found in a table, otherwise the message that is not found in the database is obtained.
.The problem that I detect with the alert of the function in javascript in which the variable that I am addressing is not arriving.
This is the execution of the program in the problem that I have.
Thank you very much for your time and I hope you can help me.