Ver Mensaje Individual
  #17 (permalink)  
Antiguo 10/09/2009, 19:52
cate324
 
Fecha de Ingreso: agosto-2009
Mensajes: 11
Antigüedad: 14 años, 8 meses
Puntos: 0
Respuesta: actualizar registro db mysql

este es el código con los nuevos cambios
<?php

// Conexion a la base de datos
$bd_host = "localhost";
$bd_usuario = "root";
$bd_password = "123456";
$bd_base = "ccsrc";
$conexion = mysql_connect($bd_host, $bd_usuario, $bd_password);
Mysql_select_db($bd_base, $conexion);
$resultados = mysql_query("SELECT * FROM habitantes ");


// Actualizar, solo se ejecuta si se persiona el boton actualizar
if(isset($_POST['boton_actualizar'])) {

//recibo las variables
$idCI = $_POST['cedula']; //Esto es lo que me indica cual de todos actualizar
$nombres = $_POST['nombresact'];
$apellidos = $_POST['apellidos'];
$fn = $_POST['nacimiento'];
$c=$_POST['civil'];
$direccion=$_POST['direccion'];
$telr = $_POST['telr'];
$telm = $_POST['telm'];
$ocupacion=$_POST['ocupacion'];
$ingreso=$_POST['ingresos'];
$observaciones=$_POST['observaciones'];

//la actualizacion en si
$actualizar = mysql_query("UPDATE habitantes SET nombres='$nombres', apellidos='$apellidos',
fechan='$fn', civil='$c', direccion='$direccion', telefor='$telr', telem='$telm',
ocupacion='$ocupacion', ingresos='$ingreso', observaciones='$observaciones' WHERE idCI='$idCI' LIMIT 1");

//mensaje de exito o error
if($actualizar) echo "Actualizado con exito"; else echo "Error al actualizar";
echo "</br><a href='actualiza_habitantes.php*'>Volver atras</a>";
return; //Esto hace que no muestre el resto de la pagina

} //del if

?>


<table border='1' cellspacing='1' cellpadding='1'>
<tr>
<td>Nombres</td>
<td>Apellidos</td>
<td>F. Nacimiento</td>
<td>Estado Civil</td>
<td>Direccion</td>
<td>Tlf Fijo</td>
<td>Tlf Movil</td>
<td>Ocupacion</td>
<td>Ingresos</td>
<td>Observaciones</td>
</tr>

<?php


// Un formulario por cada habitante
while($row = mysql_fetch_array($resultados)) {

echo "<form method='POST' action='actualiza_habitantes.php*'>
<input type='hidden' name='idCI' value='$row[idCI]'>
<tr>
<td><input type=text name=nombresact size=8 maxlength=60 value=$row[nombres]></td>
<td><input type=text name=apellidos size=8 maxlength=60 value=$row[apellidos]></td>
<td><input type=text name=nacimiento size=10 maxlength=20 value=$row[fechan]></td>
<td><input type=text name=civil size=8 maxlength=20 value=$row[civil]></td>
<td><input type=text name=direccion size=8 maxlength=100 value=$row[direccion]></td>
<td><input type=text name=telr size=8 maxlength=50 value=$row[telefor]></td>
<td><input type=text name=telm size=8 maxlength=50 value=$row[telem]></td>
<td><input type=text name=ocupacion size=8 maxlength=50 value=$row[ocupacion]></td>
<td><input type=text name=ingresos size=8 maxlength=20 value=$row[ingresos]></td>
<td><input type=text name=observaciones size=12 maxlength=100 value=$row[observaciones]></td>
<td><input type=submit name='boton_actualizar' value=ACTUALIZAR></td>
</tr></form>";

}

// Cierro la conexion
Mysql_close($conexion);

?>