Good morning, I have come to tell you what I want to do and what my current code is.
It turns out that I am trying to do a multi update done, I use the "id" of the element to filter in the table and in that same element I want to modify a field. The code I have does not work for me and it took me a whole day to find a solution.
I will leave my code to help me solve it.
This is the form:
<form method="POST" action="fun/u_list_su.php">
<input type="text" id="id_producto[]" name="id_producto[]">
<input type="text" id="cantidad_producto[]" name="cantidad_producto[]">
<button type="submit">Save</button>
</form>
This is the code:
<?php
//Aqui va la conexión
$mysqli = new mysqli('localhost', 'usuario', '123456', 'mybd');
if($mysqli->connect_error){
die('Error en la conexion' . $mysqli->connect_error);
}
//A partir de acá es el codigo que tengo
if (isset($_POST['id_producto'])) {
$id_el=$_POST['id_producto'];
$cant_el=$_POST['cantidad_producto'];
$sql2 = '';
for ($count=0; $count <count($id_el) ; $count++) {
$id_el_clean = $mysqli->query($id_el[$count]);
$cant_el_clean = $mysqli->query($cant_el[$count]);
if ($id_el_clean != '' && $cant_el_clean != '') {
$sql2 .= "UPDATE products SET stock = -'$cant_el_clean' WHERE id_producto = '$id_el_clean'";
}
}
if ($sql2 != '') {
if ($mysqli->query($sql2)) {
echo "data insert";
}
else {
echo "Error";
}
}
else {
echo "Los espacios requeridos";
}
}
?>
Thanks for your help!