Hola Todos !!!
Les cuento que he intentado hacer en un solo archivo la actualización de registros de un base de datos MySQL con una consulta de registros previa utilizando select dependientes.
Utilizo 2 formularios y 2 botones, logro traer los datos que me calcule el % de incremento de precios que busco pero no logro que me actualice los datos en la base.
Aca pego el código a ver si me pueden ayudar con esto:
<?......
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
$updateSQL = sprintf("UPDATE productos SET PrecioUnidad=%s WHERE IdProducto=%s",
GetSQLValueString($_POST['PrecioUnidad'], "double"),
GetSQLValueString($_POST['IdProducto'], "text"));
mysql_select_db($database_cn, $cn);
$Result1 = mysql_query($updateSQL, $cn) or die(mysql_error());
$updateGoTo = "modificarprecios2.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
....?>
</form>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table width="450" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="160"><input name="modificarprecios" type="submit" id="modificarprecios" value="Modificar Precios" /></td>
<td width="290"><div align="right"><span class="style28">Porcentaje de Aumento:</span>
<input name="porcentaje" type="text" id="porcentaje" size="8" />
<span class="style28">%</span></div></td>
</tr>
</table>
<br />
<table width="450" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="70" height="23" bgcolor="#1C4176" class="style24"><div align="center">Cód. Prod.</div></td>
<td bgcolor="#1C4176" class="style24"><div align="center">Nombre Producto</div></td>
<td width="80" bgcolor="#1C4176" class="style24"><div align="center">Precio Actual </div></td>
<td width="80" bgcolor="#1C4176" class="style24"><div align="center">Precio Modif </div></td>
</tr>
</table>
<?php do { ?>
<table width="450" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="70" class="style25"><div align="center">
<?php echo $row_rsproductos['IdProducto']; ?></div></td>
<td class="style25"><div align="center"><?php echo $row_rsproductos['NombreProducto']; ?></div></td>
<td width="81" class="style25"><div align="center"><?php echo $row_rsproductos['PrecioUnidad']; ?></div></td>
<td width="81" class="style25"><div align="center">
<input name="PrecioUnidad" type="text" class="style29" id="PrecioUnidad" value="<?php echo number_format($row_rsproductos['PrecioUnidad']*(1+(10/100)),2); ?>" size="8" />
</div></td>
</tr>
</table>
<input type="hidden" name="IdProducto" value="<?php echo $row_rsproductos['IdProducto']; ?>">
<input type="hidden" name="MM_update" value="form1">
<?php } while ($row_rsproductos = mysql_fetch_assoc($rsproductos)); ?><p> </p>
</form>