Foros del Web » Programando para Internet » PHP »

modificar registros de una db con mysql php

Estas en el tema de modificar registros de una db con mysql php en el foro de PHP en Foros del Web. hola que tal espero me puedan ayudar en lo siguiente. tengo una bd a la cual le quiero realizar modificaciones pero al enviar los datos ...
  #1 (permalink)  
Antiguo 16/02/2014, 21:23
 
Fecha de Ingreso: julio-2013
Mensajes: 123
Antigüedad: 10 años, 9 meses
Puntos: 1
modificar registros de una db con mysql php

hola que tal espero me puedan ayudar en lo siguiente. tengo una bd a la cual le quiero realizar modificaciones pero al enviar los datos no me manda error pero no me los modifica.

este es mi formulario de busqueda.

Código PHP:
<body>
<
br />
<
form id="registra" name="registra" method="post" action="result_buscar_modificar_registro.php">
<
table width="680" height="0%" border="0" align="center" cellpadding="0" cellspacing="0">
    <
tr>           
  
    <
td height="25">Ingrese número de factura a ubicar:</td>
    <
td height="25"><input type="text" name="factura" id="factura" /></td><td height="25"><input type="submit" name="Buscar" value="Buscar"/></td>
 
</
form>
</
body>
</
html
este es el resultado de la busqueda:

Código PHP:
</head>
<body>
<br />
<form id="registra" name="registra" method="post" action="actualiza.php">             
         <?php
include ("../conexion/conecta.php");
$factura=$_POST['factura'];
$con=mysql_connect ($host,$user,$pass) or die ("problemas con la conexion al server");
  
mysql_select_db ($db,$con) or die ("Error en la base de datos");
    
$result=mysql_query("SELECT * FROM facturar WHERE FACTURA='$_POST[factura]'"$con); 
    if (
$row mysql_fetch_array($result)){

  
?>
  <table  border="0" cellspacing="0" cellpadding="4" align="center">
              <tr>
           <td></td>
              <td><p align="center"></p></td>
              <td></td>
              </tr><tr>
<td></td><td>
<table bordercolor="#D2D2D2" cellpadding="1" cellspacing="0" align=center border=1 width="100%">
 <tr> 
 <th colspan=4> Registro de Facturas </th>
</tr>
<tr>
  <td colspan=2>Número de factura:</td>
  <td colspan=2> <input type="text" name="factura" value="<?php echo $row["factura"]?>" /></td>
<tr>
  <td colspan=2>Lugar de Emisión:</td>
  <td colspan=2><input type="text" name="emision"value="<?php echo $row["emision"]?>" /></td>
</tr>
<tr><td colspan="2">Fecha de Emisión: </td>
<td><input type="text" size="20" name="fcha"value="<?php echo $row["fcha"]?>" /></td>
</tr>
<tr>
  <td colspan=2>Nombre o Razón Social:</td>
  <td colspan=2><input type="text" name="razon_social" value="<?php echo $row["razon_social"]?>" /></td>
</tr>
<tr>
  <td colspan=2>Nº R.I.F/ C.I:</td>
  <td colspan=2><input type="text" name="rif_ci" value="<?php echo $row["rif_ci"]?>" /></td>
</tr>
<tr> 
 <th colspan=4> Registre datos descriptivos</th>
</tr>
<tr>
  <td colspan=2>Cantidad horas Trabajadas: </td>
  <td colspan=2><input type="text" name="horas_trabajadas" value="<?php echo $row["horas_trabajadas"]?>" /></td>
</tr>
<tr>
  <td colspan=2>Concepto O Descripción:</td>
  <td colspan=2> <textarea cols="19" rows="3" name="concepto"class="transforme2"><?php echo $row ["concepto"]?></textarea></td>
</tr>
<tr>
  <td colspan=2>P./ Unit:</td>
  <td colspan=2><input type="text" name="p_unit" value="<?php echo $row["p_unit"]?>" c/></td>
</tr>
<tr>
  <td colspan=2>Total :</td>
  <td colspan=2><input type="text" name="total" value="<?php echo $row["total"]?>" c/></td>
</tr>
<tr>
  <td colspan=2>Periodo :</td>
  <td colspan=2><input type="text" name="periodo" value="<?php echo $row["periodo"]?>" c/></td>
</tr>
<tr>
<td colspan=2>Total Neto a Pagar :</td>
  <td colspan=2><input type="text" name="total_pagar"value="<?php echo $row["total_pagar"]?>" class="transforme2" onFocus="this.className='transforme2'" onblur="this.className='transforme3'"/></td>
</tr>
</table></td>   </tr>           
        </table>   
  <table width="11%" height="6" border="0" align="center" bordercolor="#D2D2D2">
  <tr><td><input type='hidden'  name='factura' value='$factura'>   <input type="submit"     size="10" onclick="return confirm('¿Deseas realmente modificar la factura&nbsp;<?php echo $row["factura"]?>?')"  value="Modificar"></a></td></tr>
  </table>
   <?php
   
     
while ($row mysql_fetch_array($result));          
} else { 
echo 
"¡ No se ha encontrado ningún registro !"

?><
</table>
</form>
</body>
</html>
este es el codigo modifar

Código PHP:
<html> 

<head> 
<title>Actualizacion completada.</title>
</head> 
<body> 
<?php 
include ("../conexion/conecta.php");
$factura = ($_POST['factura']); 
$emision = ($_POST['emision']); 
$fcha = ($_POST['fcha']); 
$razon_social = ($_POST['razon_social']); 
$rif_ci = ($_POST['rif_ci']); 
$horas_trabajadas = ($_POST['horas_trabajadas']); 
$concepto = ($_POST['concepto']); 
$p_unit = ($_POST['p_unit']); 
$total = ($_POST['total']); 
$periodo = ($_POST['periodo']);
$total_pagar = ($_POST['total_pagar']); 
$con=mysql_connect ($host,$user,$pass) or die ("problemas con la conexion al server");
  
mysql_select_db ($db,$con) or die ("Error en la base de datos");
$q "UPDATE facturar Set factura='$factura',emision='$emision', fcha='$fcha', razon_social='$razon_social', rif_ci='$rif_ci', horas_trabajadas='$horas_trabajadas', concepto='$concepto', p_unit='$p_unit', total='$total', periodo='$periodo', total_pagar='$total_pagar' WHERE factura='factura'";
mysql_query($q$con) or die ("problema con query");

    echo 
'<p>Los datos se han modificado correctamente.</p>';

?> 

</body> 

</html>
  #2 (permalink)  
Antiguo 16/02/2014, 21:56
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 4 meses
Puntos: 2658
Respuesta: modificar registros de una db con mysql php

En principio, si no genera un error, pero no hace un UPDATE, la consecuencia lógica es que no hay registros que cumplan con la condición peusta en el WHERE...

¿lo meditaste?

Por otro lado, yo le veo un problema de lógica:
Código SQL:
Ver original
  1. UPDATE facturar
  2. SET factura='$factura',
  3.      emision='$emision',
  4.      fcha='$fcha',
  5.      razon_social='$razon_social',
  6.      rif_ci='$rif_ci',
  7.      horas_trabajadas='$horas_trabajadas',
  8.      concepto='$concepto',
  9.      p_unit='$p_unit',
  10.      total='$total',
  11.      periodo='$periodo',
  12.      total_pagar='$total_pagar'
  13. WHERE factura='factura'
Según esto, estás actualizando el campo "factura" (¿por qué?), y otro conjunto de datos, donde el contenido de ese mismo campo sea "factura"...
¿Estás seguro de que ese campo contiene el texto "factura"?
¿Por qué, si ya tiene algo definido lo estás cambiando por el contenido de una variable?
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)
  #3 (permalink)  
Antiguo 16/02/2014, 22:52
 
Fecha de Ingreso: julio-2013
Mensajes: 123
Antigüedad: 10 años, 9 meses
Puntos: 1
Respuesta: modificar registros de una db con mysql php

gracias por tu respuesta, si medite que al enviar a modificar los datos no me envia nada.

en primer instancia revise el código donde obtengo mi consulta y cambio los valores de los campos y mando a modificar. y no veo error.

Código PHP:
Ver original
  1. </head>
  2. <body>
  3. <br />
  4. <form id="registra" name="registra" method="post" action="actualiza.php">              
  5.          <?php
  6. include ("../conexion/conecta.php");
  7. $factura=$_POST['factura'];
  8. $con=mysql_connect ($host,$user,$pass) or die ("problemas con la conexion al server");
  9.   mysql_select_db ($db,$con) or die ("Error en la base de datos");
  10.     $result=mysql_query("SELECT * FROM facturar WHERE FACTURA='$_POST[factura]'", $con);  
  11.     if ($row = mysql_fetch_array($result)){
  12.  
  13.   ?>
  14.   <table  border="0" cellspacing="0" cellpadding="4" align="center">
  15.               <tr>
  16.            <td></td>
  17.               <td><p align="center"></p></td>
  18.               <td></td>
  19.               </tr><tr>
  20. <td></td><td>
  21. <table bordercolor="#D2D2D2" cellpadding="1" cellspacing="0" align=center border=1 width="100%">
  22.  <tr>  
  23.  <th colspan=4> Registro de Facturas </th>
  24. </tr>
  25. <tr>
  26.   <td colspan=2>Número de factura:</td>
  27.   <td colspan=2> <input type="text" name="factura" value="<?php echo $row["factura"]?>" /></td>
  28. <tr>
  29.   <td colspan=2>Lugar de Emisión:</td>
  30.   <td colspan=2><input type="text" name="emision"value="<?php echo $row["emision"]?>" /></td>
  31. </tr>
  32. <tr><td colspan="2">Fecha de Emisión: </td>
  33. <td><input type="text" size="20" name="fcha"value="<?php echo $row["fcha"]?>" /></td>
  34. </tr>
  35. <tr>
  36.   <td colspan=2>Nombre o Razón Social:</td>
  37.   <td colspan=2><input type="text" name="razon_social" value="<?php echo $row["razon_social"]?>" /></td>
  38. </tr>
  39. <tr>
  40.   <td colspan=2>Nº R.I.F/ C.I:</td>
  41.   <td colspan=2><input type="text" name="rif_ci" value="<?php echo $row["rif_ci"]?>" /></td>
  42. </tr>
  43. <tr>  
  44.  <th colspan=4> Registre datos descriptivos</th>
  45. </tr>
  46. <tr>
  47.   <td colspan=2>Cantidad horas Trabajadas: </td>
  48.   <td colspan=2><input type="text" name="horas_trabajadas" value="<?php echo $row["horas_trabajadas"]?>" /></td>
  49. </tr>
  50. <tr>
  51.   <td colspan=2>Concepto O Descripción:</td>
  52.   <td colspan=2> <textarea cols="19" rows="3" name="concepto"class="transforme2"><?php echo $row ["concepto"]?></textarea></td>
  53. </tr>
  54. <tr>
  55.   <td colspan=2>P./ Unit:</td>
  56.   <td colspan=2><input type="text" name="p_unit" value="<?php echo $row["p_unit"]?>" c/></td>
  57. </tr>
  58. <tr>
  59.   <td colspan=2>Total :</td>
  60.   <td colspan=2><input type="text" name="total" value="<?php echo $row["total"]?>" c/></td>
  61. </tr>
  62. <tr>
  63.   <td colspan=2>Periodo :</td>
  64.   <td colspan=2><input type="text" name="periodo" value="<?php echo $row["periodo"]?>" c/></td>
  65. </tr>
  66. <tr>
  67. <td colspan=2>Total Neto a Pagar :</td>
  68.   <td colspan=2><input type="text" name="total_pagar"value="<?php echo $row["total_pagar"]?>" class="transforme2" onFocus="this.className='transforme2'" onblur="this.className='transforme3'"/></td>
  69. </tr>
  70. </table></td>   </tr>            
  71.         </table>    
  72.   <table width="11%" height="6" border="0" align="center" bordercolor="#D2D2D2">
  73.   <tr><td><input type='hidden'  name='factura' value='$factura'>   <input type="submit"     size="10" onclick="return confirm('¿Deseas realmente modificar la factura&nbsp;<?php echo $row["factura"]?>?')"  value="Modificar"></a></td></tr>
  74.   </table>
  75.    <?php
  76.    
  77.      while ($row = mysql_fetch_array($result));          
  78. } else {  
  79. echo "¡ No se ha encontrado ningún registro !";  
  80. }  
  81. ?><
  82. </table>
  83. </form>
  84. </body>

aqui quiero cambiar tambien el campo factura.

Código SQL:
Ver original
  1. UPDATE facturar
  2. SET factura='$factura',
  3.      emision='$emision',
  4.      fcha='$fcha',
  5.      razon_social='$razon_social',
  6.      rif_ci='$rif_ci',
  7.      horas_trabajadas='$horas_trabajadas',
  8.      concepto='$concepto',
  9.      p_unit='$p_unit',
  10.      total='$total',
  11.      periodo='$periodo',
  12.      total_pagar='$total_pagar'
  13. WHERE factura='factura'
  #4 (permalink)  
Antiguo 16/02/2014, 23:25
 
Fecha de Ingreso: julio-2013
Mensajes: 123
Antigüedad: 10 años, 9 meses
Puntos: 1
Respuesta: modificar registros de una db con mysql php

Muchas gracias por la ayuda, gracias a tu comentario pude resolver, efecto el error estaba en la condición del where. saludo2

Etiquetas: fecha, formulario, html, modificar, mysql, registro, registros, select, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:27.