I have the following code that generates a table in php, returning the data saved in a database in mysql
require("conexion.php");
$consulta = mysqli_query($conexion, "SELECT * FROM clientes");
if (!$consulta) {
die("Fallo al realizar la consulta");
}
echo ("<table border='1px'>");
echo ("<th> NOMBRE </th> <th> MEDIO DE PAGO </th> <th>PLAN CONTRATADO</th> <th> MODIFICAR </th> <th> ELIMINAR </th>");
while ($clientes = mysqli_fetch_array($consulta)) {
echo ("<tr>");
echo ("<td>$clientes[nombre]</td>");
echo ("<td>$clientes[medioPago]</td>");
echo ("<td>$clientes[plan]</td>");
echo ("<td><a href='modificar.php?idC=$clientes[id]'>Modificar </a></td>");
echo ("<td><a href='eliminar.php'>Eliminar </a></td>");
echo ("</tr>");
}
echo ("</table>");
As you can see, each record also generates a link that takes me to the page modify.php to modify the data if necessary. With idC = $ clients [id] I get the ID of the client that I want to modify. In my file modify.php I have the following code
<form action="modificar.php">
<label>Nuevo nombre: </label>
<input type="text" name="nuevoNombre" placeholder="Ingrese el nuevo nombre">
<label>Medio de pago: </label>
<select name="nuevoMedioPago">
<option value="tarjeta">Tarjeta de credito</option>
<option value="rapipago">Rapipago - Pagofacil</option>
<option value="deposito">Deposito</option>
<option value="efectivo">Efectivo</option>
<option value="otro">Otro</option>
</select>
<label>Nuevo plan contratado: </label>
<select name="nuevoPlanContratado">
<option value="basico">Basico</option>
<option value="avanzado">Avanzado</option>
<option value="profesional">Profesional</option>
</select>
<input type="submit" value="Modificar">
</form>
<?php
require("conexion.php");
$idCliente = $_GET['idC'];
echo ("Modificaras los datos del cliente cuya ID es: $idCliente <br>" );
$consulta = mysqli_query($conexion, "SELECT * FROM clientes WHERE id = $idCliente");
while ($mostrar = mysqli_fetch_array($consulta)) {
echo ("Nombre: $mostrar[nombre] <br>");
echo ("Medio de pago: $mostrar[medioPago] <br>");
echo ("Plan: $mostrar[plan] <br>");
}
////////////////////////////ACTUALIZACION////////////////////////////
$nuevoNombre = ['nuevoNombre'];
$nuevoMedioPago = ['nuevoMedioPago'];
$nuevoPlanContratado = ['nuevoPlanContratado'];
$actualizar = mysqli_query($conexion, "UPDATE clientes SET nombre='$nuevoNombre' , medioPago='$nuevoMedioPago' , plan='$nuevoPlanContratado' WHERE id = $idCliente");
if (!$actualizar) {
die("Fallo al actualizar los datos");
}
?>
Which throws me an error in the line where I have my sql query to update the data. In case I use GET or POST both in the form and at the time of obtaining the new name, etc. the error that throws at me is Undefined index .
Greetings and thanks.