I have a problem with a form, I send the variables by post and keep in trouble, but I get a warning Notice: Undefined index: afterwards in C: \ wamp64 \ www \ model \ edit_productos2.php on line 47 and I do not know what can be wrong
<form action="" method="post">
<table border="1" align="center" id='usuarios' cellspacing="1" cellpadding="1">
<tr>
<th>Producto</th>
<th>Cantidad</th>
<th>Ingreso</th>
</tr>
<tr class='item2'>
<td>
<input type="text" class="cajas" value="<?php echo $row->nombre; ?>" disabled>
</td>
<td>
<input type="text" class="cajas" value="<?php echo $row->existencia; ?>" disabled>
</td>
<td>
<input type="number" id="despues" class="cajas" value="0" name="despues" onchange="return validanumero(this)" required>
</td>
</table>
</br></br>
<input type="submit" class="boton" name="submit" value="Aceptar">
<input id="boton" class="boton" type="button" value="Cancelar" onclick="window.location = '../vista/administracion_productos.php'">
</form>
<?php
$antes = $row->existencia;
$var = $_POST['despues'];
$total = $antes+$var;
if (isset($_POST['submit'])) {
$field = array("existencia" => $total);
$tbl = "productos";
edit($tbl, $field, 'id_prod', $id);
echo "<script language='javascript'>window.location='../vista/administracion_productos.php'</script>";
}
?>
</div>
The code of the page that records the change in the bd
function edit($tblname, $form_data, $field_id, $id) {
$sql = "UPDATE " . $tblname . " SET ";
$data = array();
foreach ($form_data as $column => $value) {
$data[] = $column . "=" . "'" . $value . "'";
}
$sql .= implode(',', $data);
$sql .= " where " . $field_id . " = '" . $id . "'";
return db_query($sql);
}
in line 47 is where I assign the field to a variable to operate it
$var = $_POST['despues'];
Thank you very much for your collaboration