Ver Mensaje Individual
  #6 (permalink)  
Antiguo 24/10/2014, 10:25
alanpacindo
 
Fecha de Ingreso: octubre-2014
Ubicación: Mexico
Mensajes: 9
Antigüedad: 9 años, 7 meses
Puntos: 0
Respuesta: Problemas con php y mysql en Formulario para actualizar

Explico:

1.- Del Formulario: form_cambios.php despliega todos los registros de la BD y le añade un campo: "Accion", el cual con la varieble $clave identificara el reg a modificar y el valor se obtiene del $renglon['clave'] el cual asu vez se obtiene de mysql_fetch_array.

2.- En el Formulario form_cambios_resultado.php despliega todos los campos del registro y los coloca en los input para modificar el contenido incluyendo la clave.

Notas: En este punto se visualizan los campos con los valores correspondientes a ese registro en los INPUT

3.- El Formulario cambios.php es el encargado de realizar los cambios ya en la BD por medio de la variable $clave obtiene su valor por medio de la siguiente asignación $clave=$v2; (este cambio es por tu sugerencia)

En este punto y realizando un ECHO "$sql"; se obtiene lo siguiente:

UPDATE productos SET clave=22, producto=`XXXXX`, modelo=`XXXXX`, descripcion=`XXXXX`, proveedor=`XXXXX`, precio_e=300, precio_s1=800, precio_s2=700, precio_s3=600, precio_s4=500, notas=`XXXXX`, existencia=100 WHERE clave=22

y no da Error pero no actualiza la BD.... OJO

/* ------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------- */
/* FORM_CAMBIOS.PHP ------------------------------------------------ */
/* ------------------------------------------------------------------------------- */
<!DOCTYPE html>
<html lang="es">
<head>
<title>Titulo</title>
<meta charset="utf-8">
<link href="css/estilos.css" rel="stylesheet" type="text/css" media="all">
<script>
function cancelar(){
location.href='index.php';
}
</script>
</head>
<body>
<h1>Inventario</h1>
<hr>
<h2>Herramientas del Inventario [CAMBIOS]</h2>
<hr>
<?php
require("conexion.php");

$sql="select * from productos";
$datos=mysql_query($sql,$con);

echo "<table border='1'>";

echo "<th>Clave</th>
<th>Producto</th>
<th>Modelo</th>
<th>Descripcion</th>
<th>Proveedor</th>
<th>Precio de Compra</th>
<th>Precio de Salida1</th>
<th>Precio de Salida2</th>
<th>Precio de Salida3</th>
<th>Precio de Salida4</th>
<th>Notas</th>
<th>Existencia</th>
<th>Accion</th>";

while($renglon=mysql_fetch_array($datos)) {
echo "<tr>";
echo "<td>" . $renglon['clave'] . "</td>";
echo "<td>" . $renglon['producto'] . "</td>";
echo "<td>" . $renglon['modelo'] . "</td>";
echo "<td>" . $renglon['descripcion'] . "</td>";
echo "<td>" . $renglon['proveedor'] . "</td>";
echo "<td>" . $renglon['precio_e'] . "</td>";
echo "<td>" . $renglon['precio_s1'] . "</td>";
echo "<td>" . $renglon['precio_s2'] . "</td>";
echo "<td>" . $renglon['precio_s3'] . "</td>";
echo "<td>" . $renglon['precio_s4'] . "</td>";
echo "<td>" . $renglon['notas'] . "</td>";
echo "<td>" . $renglon['existencia'] . "</td>";
echo "<td>" . "<a href='form_cambios_resultado.php?clave=" . $renglon['clave'] . "'>Cambiar</a>" . "</td>";
echo "</tr>";
}
echo "</table>";
?>
<br>
<input type="button" value="Cancelar" onClick="cancelar()" />
<footer>
<hr>
Pie de Pagina
</footer>
</body>
</html>

/* FORM_CAMBIOS_RESULTADO.PHP ---------------------------- */
/* ------------------------------------------------------------------------------- */

<!DOCTYPE html>
<html lang="es">
<head>
<title>Titulo</title>
<meta charset="utf-8">
<link href="css/estilos.css" rel="stylesheet" type="text/css" media="all">
<script>
function cancelar(){
location.href='index.php';
}
</script>
</head>
<body>
<h1>Inventario</h1>
<hr>
<h2>Herramientas del Inventario [CAMBIOS]</h2>
<ul>
<li><a href="index.php">Regresar</a></li>
</ul>
<hr>
<h2>Sección CAMBIOS</h2>
<?php
require("conexion.php");

$clave = $_REQUEST[ 'clave' ];
$sql="select * from productos where clave='$clave'";

$datos=mysql_query($sql,$con);
$renglon=mysql_fetch_array($datos);
?>
<form method="post" action="cambios.php">
<table>
<tr>
<td><label>Clave:</label></td>
<td><input type="number" name="t_clave" value="<?php echo $renglon['clave']; ?>" ></td>
</tr>
<tr>
<td><label>Producto:</label></td>
<td><input type="text" name="t_producto" value="<?php echo $renglon['producto']; ?>"></td>
</tr>
<tr>
<td><label>Modelo:</label></td></td>
<td><input type="text" name="t_modelo" value="<?php echo $renglon['modelo']; ?>"></td>
</tr>
<tr>
<td><label>Descripción:</label></td>
<td><input type="text" name="t_descripcion" value="<?php echo $renglon['descripcion']; ?>"></td>
</tr>
<tr>
<td><label>Proveedor:</label></td>
<td><input type="text" name="t_proveedor" value="<?php echo $renglon['proveedor']; ?>"></td>
</tr>
<tr>
<td><label>Precio de Compra:</label></td>
<td><input type="text" name="t_precio_e" value="<?php echo $renglon['precio_e']; ?>"></td>
</tr>
<tr>
<td><label>Precio de Venta 1:</label></td>
<td><input type="text" name="t_precio_s1" value="<?php echo $renglon['precio_s1']; ?>"></td>
</tr>
<tr>
<td><label>Precio de Venta 2:</label></td>
<td><input type="text" name="t_precio_s2" value="<?php echo $renglon['precio_s2']; ?>"></td>
</tr>
<tr>
<td><label>Precio de Venta 3:</label></td>
<td><input type="text" name="t_precio_s3" value="<?php echo $renglon['precio_s3']; ?>"></td>
</tr>
<tr>
<td><label>Precio de venta 4:</label></td>
<td><input type="text" name="t_precio_s4" value="<?php echo $renglon['precio_s4']; ?>"></td>
</tr>
<tr>
<td><label>Notas:</label></td>
<td><input type="text" name="t_nota" value="<?php echo $renglon['notas']; ?>"></td>
</tr>
<tr>
<td><label>Existencia:</label></td>
<td><input type="text" name="t_existencia" value="<?php echo $renglon['existencia']; ?>"></td>
</tr>
<tr>
<td></td>
<td>
<table>
<tr>
<td><input type="submit" value="Actualizar" name="btn_ok"></td>
<td><input type="reset" value="Borrar" name="btn_reset"></td>
<td><input type="button" value="Cancelar" onClick="cancelar()" /></td>
</tr>
</table>
</td>
</tr>
<br>
<table>
</form>
<footer>
<hr>
Pie de pagina
</footer>
</body>
</html>

/* CAMBIOS.PHP ---------------------------------------------------------- */
/* ------------------------------------------------------------------------------- */

<?php
require("conexion.php");

$v2 = $_REQUEST['t_clave'];
$clave=$v2;
$v3 = $_REQUEST['t_producto'];
$v4 = $_REQUEST['t_modelo'];
$v5 = $_REQUEST['t_descripcion'];
$v6 = $_REQUEST['t_proveedor'];
$v7 = $_REQUEST['t_precio_e'];
$v8 = $_REQUEST['t_precio_s1'];
$v9 = $_REQUEST['t_precio_s2'];
$v10 = $_REQUEST['t_precio_s3'];
$v11 = $_REQUEST['t_precio_s4'];
$v12 = $_REQUEST['t_nota'];
$v13 = $_REQUEST['t_existencia'];

$sql="UPDATE productos SET clave=$v2, producto=`$v3`, modelo=`$v4`, descripcion=`$v5`, proveedor=`$v6`, precio_e=$v7, precio_s1=$v8, precio_s2=$v9, precio_s3=$v10, precio_s4=$v11, notas=`$v12`, existencia=$v13`where clave=$v2";
echo "$sql";
mysql_query($sql,$con);

echo "<script>";
echo "alert('los datos han sido guardados...');";
echo "location.replace('form_cambios.php')";
// Regresa al principio
echo "</script>";
?>