I am trying to update a record in a MySQL table, by means of a script called " prueba_envio_1.php " which selects the value of the first row of the table with heading waiting when you press the call next button, when you get this information, you write it automatically in the input text to be sent by POST, once you have selected the value, again press the button that is now called end shift to end the turn.
// prueba_envio_1.php
<!doctype html>
<html lang="en">
<html>
<head>
<meta charset="UTF-8">
<title>Prueba</title>
</head>
<body>
<!-- CUERPO -->
<center>
<form name="datos_turnos" method="POST">
<div id="datos_y_turnos_liquidacion">
<div>
<label style="font-size: 35pt; color:yellow" name="estado" id="estado"></label> <!-- ETIQUETA DE ATENDIENDO : -->
<label style="font-size: 35pt; color:yellow" name="turn" id="turn"></label><br/> <!-- ETIQUETA DE TURNO SELECCIONADO -->
<input type="text" name="turno_oculto" id="turno_oculto" style="text-align: right">
<table id="tabla_turnos" name="tabla_turnos" style="font-size: 18pt; text-align:center" border="1px">
<tr>
<th style="font-size: 18pt">TURNOS EN ESPERA</th>
</tr>
<tr>
<td>I4</td>
</tr>
<tr>
<td>I5</td>
</tr>
<tr>
<td>I6</td>
</tr>
</table>
</div>
</div>
<div id="remitir_y_finalizar_liquidacion">
<div>
<button type="button" name="finalizar turno" id="BTN_FINALIZAR_TURNO" class="campana" onclick="cambio_texto('prueba_envio_2.php')" style="width:350px; height:200px; Arial; font-size: 20pt">LLAMAR SIGUIENTE</button>
</div>
</div>
</body>
</html>
<script>
// VARIABLES
var tabla = document.getElementById('tabla_turnos');
var uno = document.getElementById('BTN_FINALIZAR_TURNO');
var estado = document.getElementById('estado');
var turno = document.getElementById('turn');
var oculto = document.getElementById('turno_oculto');
// PARA CAMBIAR EL TEXTO CADA VEZ QUE SE DA CLICK EN EL BOTON (SE EJECUTA CADA VEZ QUE DAMOS CLICK AL BOTON DE LLAMAR Y FINALIZAR)
function cambio_texto(destino1) {
// ESTE IF ES PARA CUANDO PRESIONEMOS EL BOTON EN CASO DE QUERER FINALIZAR TURNO, ES DECIR CUANDO EL BOTON DIGA "FINALIZAR TURNO"
if (uno.innerHTML == 'FINALIZAR TURNO'){ // SI QUIERE FINALIZAR TURNO O LLAMAR
var respuesta = confirm('¿ ESTA SEGURO QUE DESEA FINALIZAR TURNO ?');
if(respuesta==true){ // SI RESPONDO QUE SI
uno.innerHTML = 'LLAMAR SIGUIENTE'; // CAMBIA TEXTO DEL BOTON A "LLAMAR SIGUIENTE"
estado.innerText = '';
turno.innerText = '';
document.datos_turnos.action = destino1; //
document.datos_turnos.submit(); // SE ENVIA POR POST A : prueba_envio_2.php
}
else{
}
}
else{ // ESTE ELSE ES PARA CUNADO PRESIONEMOS EL BOTON EN CASO DE QUERER LLAMAR TURNO, ES DECIR CUANDO EL BOTON DIGA "LLAMAR SIGUIENTE"
if(tabla.rows[1]){ // SI YA SELECCIONO TURNO
estado.innerHTML = 'ATENDIENDO: ';
turno.innerText = tabla.rows[1].textContent;
oculto.value = tabla.rows[1].textContent;
uno.innerHTML = 'FINALIZAR TURNO';
}
else { // NO HA SELECCIONADO TURNO
alert("NO HAY TURNOS EN ESPERA.");
}
}
}
</script>
It is assumed that at the end of the shift it sends by POST the value that is in the input text to the script prueba_envio_2.php which is responsible for receiving the data by POST and update the record with the current time in the row that corresponds to the data received, but I do not know why I do not update in the database, and I checked if the data is coming by printing it with echo in the script prueba_envio_2 .php and if it is arriving, but it does not update.
// prueba_envio_2.php
<?php
include("conexion.php");
date_default_timezone_set("America/Bogota");
setlocale(LC_ALL,"es_ES");
$fecha_actual = date("Y-m-d H:i:s");
$turno_remitido = $_POST["turno_oculto"]; // SE RECIBE LA VARIABLE POR POST
echo $turno_remitido; // IMPRIME LA VARIEBLE RECIBIDA POR POST
// ACTUALIZA LA BD DICIENDO
$_UPDATE_SQL = ("UPDATE $tabla1_bd Set
FINALIZADO = '$fecha_actual'
WHERE TURNO = '$turno_remitido'"); // ACTUALIZAMOS EN LA CELDA QUE COINCIDA CON LA VARIABLE RECIBIDA
mysqli_query($conexion,$_UPDATE_SQL);
header('Location:prueba_envio_1.php');
?>
I enclose the conexion.php script and the database table:
// conexion.php
<?php
$host = "localhost";
$usuariobd = "zona1";
$clavebd = "PrimeraZona12345";
$basededatos = "distrito_militar_7";
$tabla1_bd = "ciudadanos";
$tabla2_bd = "login";
$tabla3_bd = "remitidos";
$conexion = mysqli_connect($host,$usuariobd,$clavebd,$basededatos);
if ($conexion->connect_errno){
echo "Nuestro sistema experimenta fallos...";
exit();
}
?>
If someone knows what the error is, I appreciate your cooperation.