Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/07/2015, 23:39
diegoferrg
 
Fecha de Ingreso: mayo-2010
Mensajes: 30
Antigüedad: 14 años
Puntos: 0
Exclamación ¿Cómo actualizar registros de bases de datos MYSQL con php?

Saludos a todos los del foro
Necesito ayuda para actualizar registros de bases de datos mysql con php.


este es el ódigo que utlizo y no me funciona, no se que hacer. Si alguien me puede ayudar le pediria que me dijera de forma específica que debo hacer ya que soy novato en esto.

CODIGO:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sin título</title>
</head>

<body>
<?php
// ACA CREO LA COEXCIÓN A LABASE DE DATOS
$conexion=mysqli_connect("localhost","root","","si ndicatura") or die("Problemas con la conexión");
$registros=mysqli_query($conexion,"SELECT `id_item`, `item_pedido`, `fecha_peticion`, `costo`, `estado_aprobacion`, `nombre_quien_aprueba`, `fecha_aprobacion` FROM `registros`;") or
die("Problemas en el select:".mysqli_error($conexion)
);

// ACA LEO LA BASE DE DATOS Y LA CONVIERTO EN UN ARRAY EN PHP
$a=0;
while ($reg=mysqli_fetch_array($registros))
{
$registro [$a]=array('id_item'=>$reg['id_item'],'item_pedido'=>$reg['item_pedido'],'fecha_peticion'=>$reg['fecha_peticion'],'costo'=>$reg['costo'],'estado_aprobacion'=>$reg['estado_aprobacion'],'nombre_quien_aprueba'=>$reg['nombre_quien_aprueba'],'fecha_aprobacion'=>$reg['fecha_aprobacion']);
$a++;
}

//ACA CREO EL ENCABEZADO DE LA TABLA PARA LA PRESENTACIÓN DE LA INFORMACION DE LA BASE DE DATOS
echo "<table width='847' border='1' cellspacing='2' cellpadding='3'> \n
<tr>
<th width='85' bgcolor='#999999' scope='col'>ID ITEM</th>
<th width='195' bgcolor='#999999' scope='col'>SOLICITUD</th>
<th width='87' bgcolor='#999999' scope='col'>FECHA DE SOLICITUD</th>
<th width='72' bgcolor='#999999' scope='col'>COSTO</th>
<th width='111' bgcolor='#999999' scope='col'>ESTADO DE LA SOLICITUD</th>
<th width='115' bgcolor='#999999' scope='col'>NOMBRE DE QUIEN APRUEBA</th>
<th width='107' bgcolor='#999999' scope='col'>FECHA DE APROBACION</th>
</tr>
";
?>


<?php
//ACA IMPRIMO LA BASE DE DATOS COMO UN FORMULARIO HTML PARA ENVIARLA COMO UN FORMULARIO DE ACTUALIZACION

for($f=0;$f<count($registro);$f++)
{ ?>
<form action="" method="get">
<td><input type="text" value="<?php echo $registro [$f]['id_item']?>" name="id_item"></td>
<td><input type="text" value="<?php echo $registro[$f]['item_pedido']?>" name="item_pedido"></td>
<td><input type="text" value="<?php echo $registro[$f]['fecha_peticion']?>" name="fecha_peticion" ></td>
<td><input type="text" value="<?php echo $registro[$f]['costo']?>" name="costo"></td>
<td><input type="text" value="<?php echo $registro[$f]['estado_aprobacion']?>" name="estado_aprobacion"></td>
<td><input type="text" value="<?php echo $registro[$f]['nombre_quien_aprueba']?>" name="nombre_quien_aprueba" class="letrapequeña" ></td>
<td><input type="text" value="<?php echo $registro[$f]['fecha_aprobacion']?>" name="fecha_aprobacion"></td>
<td>
<input type="submit" value="APROBAR gastos" name="aprobar" > </form></tr>
<?php
}

// EN ESTE PUNTO NO ME REALIZA LA FUNCION DE ACTUALIZACION ***solicito ayuda aqui****

if(isset($_POST['aprobar'])){
mysqli_query($conexion,"UPDATE `sindicatura`.`registros` SET `estado_aprobacion` = 'APROBADO' WHERE `registros`.`id_item` = 1'");
}

?>

</body>
</html>