I'm trying to do an update in mysql from php, but I'm finding it difficult, since I want to collect the values of a form in which their names are put with the name of the fields of the columns, I do not know how to explain Well, I pass code to you:
<body>
<div align="center" style="font-size:40px">
<form method="post" action="aceptar-edicion.php">
<fieldset style="width:70%">
<legend>Editar marca</legend>
<?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 = $_POST['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 = "SHOW COLUMNS FROM marcas";
$resultado = mysqli_query($conexion, $sql);
while($fila = mysqli_fetch_assoc($resultado)){
echo "<label>" . ($fila['Field']) . " " . "<input type='text' name='" . $fila['Field'] . "' id='" . $fila['Field'] . "'</label></br>";
}//end while
////Cerrar conexion
mysqli_close($conexion);
?>
</br>
<input type="submit" value="Aceptar cambio"/>
</fieldset>
</form>
</div>
As you can see, I want to make labels with their respective inputs by putting the name of each column of the mysql table. That is, if I have the columns in my table "name, address, phone, email" I want to leave a label with that value and an input next to it with the "name" and the "id" called the field, until then good.
Now, I want to collect the values of those input and put them in a table already created, but I would not know how to do it, because I would have to read the columns of the table again.
<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 = $_POST['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
////////////////////////AQUÍ ES DONDE NO SE QUÉ HACER//////////////////////////
$sql = "UPDATE marcas SET ";
for($i=0; $i<= ; $i++){
echo $fila[$i] . " = '" . $_POST[$fila[$i]] . "', ";
}
echo " WHERE nombre = " . $marca . ";";
$resultado = mysqli_query($conexion, $sql);
////Cerrar conexion
mysqli_close($conexion);
?>
I do not know how I could do it, it's very difficult for me, I hope you can help me, thank you.