Overlap records in a MySQL table from PHP

1

Someone would help me to make records overlap in the same table and I have the record of everything I want to see if you can help me is to know how to overlap those records.

---+--------+----------------+------------+----------+----------+----------+----------       
Id | Nombre |     E-mail     |    Fecha   | Hora de  | Hora de  | Hora de  | Hora de
   |        |                |            | Entrada  | Comida   | Regreso  | Salida 
---+--------+----------------+------------+----------+----------+----------+----------       
28 | Carlos | Carlos90@gmail | 2008-07-17 | 00:37:42 | 00:00:00 | 00:00:00 | 00:00:00           
29 | Carlos | Carlos90@gmail | 2008-07-17 | 00:00:00 | 00:00:00 | 00:00:00 | 00:37:49   
---+--------+----------------+------------+----------+----------+----------+----------  

My question is if someone knows how to make the entry time and departure time record, are the same record, then I share the entry time code and I hope you can help me.

include "../Funciones/Conexion.php";
$mysqli = inicio();

$nombre = $_POST["nombre"];
$email = $_POST["email"];
$fecha = date('d/m/y');  
$hora = date('H:i:s');


$sql = "INSERT INTO chequeo (nombre,email,fecha,hora)
        VALUES ('$nombre','$email','$fecha','$hora');";

$query = mysqli_query($mysqli,$sql);
if ($query){
  echo "<script>alert(\"Exito al registrar.\"); </script>";
  echo "<script>location.href='../Usuario.php'</script>";
} else {
  echo "<script>alert(\"Error al registrar\"); </script>";
  echo "<script>location.href='../Usuario.php'</script>";

I also have this other one where the exit does someone can help me how to put them together so they overlap

include "../Funciones/Conexion.php";
$mysqli = inicio();

$nombre = $_POST["nombre"];
$email = $_POST["email"];
$fecha = date('d/m/y');  
$horaS = date('H:i:s');


$sql = "INSERT INTO chequeo (nombre,email,fecha,horaS)
        VALUES ('$nombre','$email','$fecha','$horaS');";

$query = mysqli_query($mysqli,$sql);
if ($query){
  echo "<script>alert(\"Exito al registrar.\"); </script>";
  echo "<script>location.href='../Usuario.php'</script>";
} else {
  echo "<script>alert(\"Error al registrar\"); </script>";
  echo "<script>location.href='../Usuario.php'</script>";
}

What I need is that my record more or less is like this

Id | Name | E-mail | Date | Entry Time | Meal Time | Time of Return of Food | Departure Time |

28 | Carlos | Carlos90 @ gmail | 2008-07-17 | 00:37:42 | 00:00:00 | 00:00:00 | 00:40:20

    
asked by iBokii 08.07.2017 в 08:26
source

1 answer

1

If I have understood correctly, what you want to do is modify the first record when a person leaves.

To do that you have to use UPDATE in site INSERT in the second code.
After SET you put the data you want to change, and after WHERE you put the data that checks the record you want to change

<?php

include "../Funciones/Conexion.php";
$mysqli = inicio();

$nombre = $_POST["nombre"];
$email = $_POST["email"];
$fecha = date('d/m/y');  
$horaS = date('H:i:s');

$sql = "UPDATE chequeo 
SET horaS = '$horaS' 
WHERE nombre = '$nombre' AND email = '$email' AND fecha = '$fecha'";

$query = mysqli_query($mysqli,$sql);
if ($query){
echo "<script>alert(\"Exito al registrar.\"); </script>";
echo "<script>location.href='../Usuario.php'</script>";
}else{
echo "<script>alert(\"Error al registrar\"); </script>";
echo "<script>location.href='../Usuario.php'</script>";
}

When you make programs that use the given data of the user I suggest you use 'prepared statements' to prevent 'sql injections'. Information: link

    
answered by 08.07.2017 в 10:42