Let's see if you can help me that for many laps I give, I can not find the error. The attached code returns me:
Notice: "Undefined offset: 0 in /var/www/vhosts/16/181528/webspace/httpdocs/sur-madrid.es/alumnos/Richard/Marcas/Administrator/aceptar-edicion.php on line 56 Notice: Undefined index: in /var/www/vhosts/16/181528/webspace/httpdocs/sur-madrid.es/alumnos/Richard/Marcas/Administrator/aceptar-edicion.php on line 56 "
I understand that the error occurs on line 56 ( $sql = "UPDATE marcas SET " . $fila[$i] . " = '" . $_POST[$fila[$i]] . "' WHERE nombre = '" . $marca . "'";
) until I get there, but I do not get to know the reason for the failure, I hope you can help me, thanks. The code is as follows:
<body>
<?php
ini_set('display_errors', 'On');
// Valor por defecto en PHP
// Muestra todos los errores menos las notificaciones
error_reporting(E_ALL ^ E_NOTICE);
// Muestro todos los errores
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
error_reporting(E_ALL);
error_reporting(-1);
// Muestro todos los errores, incluso los estrictos
error_reporting(E_ALL | E_STRICT);
// No muestra ningún error
error_reporting(0);
// También se puede usar la función ini_set
ini_set('error_reporting', E_ALL);
//// Recoger variables ////
$marca = $_GET['marca'];
////Datos db
$usuario = "usuario";
$password = "pass";
$servidor = "server";
$basededatos = "bd";
////Crear conexion
$conexion = mysqli_connect($servidor, $usuario, $password)
or die("No se ha podido conectar a la base de datos");
////Seleccionar db
$db = mysqli_select_db($conexion, $basededatos)
or die("Uppppss! No se ha podido conectar a la base de datos");
////Establecer y realizar consulta
$sql = "SELECT * FROM marcas";
$resultado = mysqli_query($conexion, $sql);
$fila = mysqli_fetch_assoc($resultado);
for($i=0; $i<=mysqli_num_fields($resultado); $i++){
$sql = "UPDATE marcas SET " . $fila[$i] . " = '" . $_POST[$fila[$i]] . "' WHERE nombre = '" . $marca . "'";
$resultado = mysqli_query($conexion, $sql);
}
////Cerrar conexion
mysqli_close($conexion);
?>