Good morning I'm doing an exercise in which they ask me to do an ABM form and I did it in the following way
this would be the file edit.php where is the update button that leads to another page to edit the data and then update them in the index
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sin título</title>
<link rel="stylesheet" type="text/css" href="hoja.css">
</head>
<body>
<h1>ACTUALIZAR</h1>
<?php
include("conexion.php");
if(!isset($_POST["bot_actualizar"])){
$Id=$_GET["IdCliente"];
$Nombre=$_GET["Nombre"];
$Apellido=$_GET["Apellido"];
$Direccion=$_GET["Direccion"];
}else{
$Id=$_POST["IdCliente"];
$Nombre=$_POST["Nombre"];
$Apellido=$_POST["Apellido"];
$Direccion=$_POST["Direccion"];
$consulta="UPDATE cliente SET Nombre=:clinom, Apellido=:cliape, Direccion=:clidir WHERE IdCliente=:cliid";
$resultado=$conexion->prepare($consulta);
$resultado->execute(array(":cliid"=>$Id, ":clinom"=>$Nombre, ":cliape"=>$Apellido, ":clidir"=>$Direccion));
header("location:index.php");
}
?>
<p>
</p>
<p> </p>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<table width="25%" border="0" align="center">
<tr>
<td></td>
<td><label for="IdCliente"></label>
<input type="hidden" name="IdCliente" id="IdCliente"></td>
</tr>
<tr>
<td>Nombre</td>
<td><label for="Nombre"></label>
<input type="text" name="Nombre" id="Nombre" value="<?php echo $Nombre?>"></td>
</tr>
<tr>
<td>Apellido</td>
<td><label for="Apellido"></label>
<input type="text" name="Apellido" id="Apellido" value="<?php echo $Apellido?>"></td>
</tr>
<tr>
<td>Dirección</td>
<td><label for="Direccion"></label>
<input type="text" name="Direccion" id="Direccion" value="<?php echo $Direccion?>"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="bot_actualizar" id="bot_actualizar" value="Actualizar"></td>
</tr>
</table>
</form>
<p> </p>
</body>
</html>
This second code belongs to index.php (it's only a fragment)
<?php
foreach($registros as $clientes): ?>
<tr>
<td><?php echo $clientes->IdCliente?> </td>
<td><?php echo $clientes->Nombre?></td>
<td><?php echo $clientes->Apellido?></td>
<td><?php echo $clientes->Direccion?></td>
<td class="bot"><a href="borrar.php?Direc=<?php echo $clientes->Direccion?>"><input type='button' name='del' id='del' value='Borrar'></a></td>
<td class='bot'><a href="editar.php?IdCliente=<?php echo $clientes->IdCliente?> & Nombre=<?php echo $clientes->Nombre?> & Apellido=<?php echo $clientes->Apellido?> & Direccion=<?php echo $clientes->Direccion?>"><input type='button' name='up' id='up' value='Actualizar'></a></td>
</tr>
<?php
and finally (by the doubts) the third one that is the one of the connection.php
<?php
try{
$conexion=new PDO('mysql:host=localhost; dbname=cliente_factura', 'root', '');
$conexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conexion->exec("Set character set utf8");
}catch (Exception $e){
die('Error' . $conexion->getMessage());
echo "Linea de error" . $conexion->getLine();
}
?>
And doing all this still does not update the data that I change on the other page and that, supposedly, should return to the index.php
I do not know what the error is