I would like to make a web system which shows me the X client (ID) history and I have the complete crud but at the point of how to create a history as the client asks me unfortunately I do not know how it is done.
Explanation in detail of what I need:
The customer is a tire dealer and needs that when for example I store a Data and which is identified with the ID for example, it needs that when they click on a Data already stored in a database it shows the history of that data.
Example in production:
Save JUAN on Wednesday - > and he made two entry and exit in his work the day the time and date
Code:
Update.php
<?php
//Compara para ver si existe algo como indica el codigo si no existe un POST
//Mandame hasta el Eelse
if(!empty($_POST)){
/*Compara para ver si los campos agreados al POST (input en el html) esta vacion y si lo estan me manda al else y si no ejecuta la connecion*/
if(isset($_POST["name"]) &&isset($_POST["lastname"]) &&isset($_POST["email"]) &&isset($_POST["address"]) &&isset($_POST["phone"])){
if($_POST["name"]!=""&& $_POST["lastname"]!=""&&$_POST["address"]!=""){
//crea la conexion a la base de datos
include "conexion.php";
/*Ejecuta update a la tabla atravez de la variable $sql y agrega los datos*/
$sql = "update person set name=\"$_POST[name]\",lastname=\"$_POST[lastname]\",email=\"$_POST[email]\",address=\"$_POST[address]\",phone=\"$_POST[phone]\" where id=".$_POST["id"];
//se insertan los datos
$query = $con->query($sql);
//si ya se termino osea ni no manda nada y todo salio bien me muestra el IF
if($query!=null){
print "<script>alert(\"Actualizado exitosamente.\");window.location='../ver.php';</script>";
//sino me sale el else
}else{
print "<script>alert(\"No se pudo actualizar.\");window.location='../ver.php';</script>";
}
}
}
}
?>
add.php
<?php
if(!empty($_POST)){
if(isset($_POST["name"]) &&isset($_POST["lastname"]) &&isset($_POST["email"]) &&isset($_POST["address"]) &&isset($_POST["phone"])){
if($_POST["name"]!=""&& $_POST["lastname"]!=""&&$_POST["address"]!=""){
include "conexion.php";
$sql = "insert into person(name,lastname,email,address,phone,created_at) value (\"$_POST[name]\",\"$_POST[lastname]\",\"$_POST[email]\",\"$_POST[address]\",\"$_POST[phone]\",NOW())";
$query = $con->query($sql);
if($query!=null){
print "<script>alert(\"Agregado exitosamente.\");window.location='../ver.php';</script>";
}else{
print "<script>alert(\"No se pudo agregar.\");window.location='../ver.php';</script>";
}
}
}
}
?>
Search.php
<?php
include "conexion.php";
$user_id=null;
$sql1= "select * from person where name like '%$_GET[s]%' or lastname like '%$_GET[s]%' or address like '%$_GET[s]%' or email like '%$_GET[s]%' or phone like '%$_GET[s]%' ";
$query = $con->query($sql1);
?>
<?php if($query->num_rows>0):?>
<table class="table table-bordered table-hover">
<thead>
<th>Nombre</th>
<th>Apellido</th>
<th>Email</th>
<th>Direccion</th>
<th>Telefono</th>
<th></th>
</thead>
<?php while ($r=$query->fetch_array()):?>
<tr>
<td><?php echo $r["name"]; ?></td>
<td><?php echo $r["lastname"]; ?></td>
<td><?php echo $r["email"]; ?></td>
<td><?php echo $r["address"]; ?></td>
<td><?php echo $r["phone"]; ?></td>
<td style="width:150px;">
<a href="./editar.php?id=<?php echo $r["id"];?>" class="btn btn-sm btn-warning">Editar</a>
<a href="#" id="del-<?php echo $r["id"];?>" class="btn btn-sm btn-danger">Eliminar</a>
<script>
$("#del-"+<?php echo $r["id"];?>).click(function(e){
e.preventDefault();
p = confirm("Estas seguro?");
if(p){
window.location="./php/eliminar.php?id="+<?php echo $r["id"];?>;
}
});
</script>
</td>
</tr>
<?php endwhile;?>
</table>
<?php else:?>
<p class="alert alert-warning">No hay resultados</p>
<?php endif;?>
I think that in the previous one, the problem is not because I think so.
table.php - where it shows the data
<?php
include "conexion.php";
$user_id=null;
$sql1= "select * from person";
$query = $con->query($sql1);
?>
<?php if($query->num_rows>0):?>
<table class="table table-bordered table-hover">
<thead>
<th>Nombre</th>
<th>Apellido</th>
<th>Email</th>
<th>Direccion</th>
<th>Telefono</th>
<th></th>
</thead>
<?php while ($r=$query->fetch_array()):?>
<tr>
<td><?php echo $r["name"]; ?></td>
<td><?php echo $r["lastname"]; ?></td>
<td><?php echo $r["email"]; ?></td>
<td><?php echo $r["address"]; ?></td>
<td><?php echo $r["phone"]; ?></td>
<td style="width:150px;">
<a href="./editar.php?id=<?php echo $r["id"];?>" class="btn btn-sm btn-warning">Editar</a>
<a href="#" id="del-<?php echo $r["id"];?>" class="btn btn-sm btn-danger">Eliminar</a>
<script>
$("#del-"+<?php echo $r["id"];?>).click(function(e){
e.preventDefault();
p = confirm("Estas seguro?");
if(p){
window.location="./php/eliminar.php?id="+<?php echo $r["id"];?>;
}
});
</script>
</td>
</tr>
<?php endwhile;?>
</table>
<?php else:?>
<p class="alert alert-warning">No hay resultados</p>
<?php endif;?>