modificacion de datos
Publicado por congas1983 (29 intervenciones) el 01/10/2007 18:24:09
señores tengo problemas con este codigo fuente para modificar los datos de una tabla
este codigo me busca el dato a modificar y me lo trae a una tabla
<?
$txtmodificar=$_REQUEST['txtmodificar'];
$cn=mysql_connect("localhost","root","")or die ("no se puede establecer la conexion");
mysql_select_db("sisbagir");;
$consulta = "select * from ensayo where cedula = '$txtmodificar'";
$resultado = mysql_query($consulta);
$numreg = mysql_num_rows($resultado);
if($numreg == 0)
{
echo "No existen registros";
}
else
{
while($filas = mysql_fetch_array($resultado))
{
?>
</font>
<center> <font size = "5" color = "#FFFFFF" face = "arial black" class = "blur"> Modificar </font>
</center>
<form action = "modificar.php" method = "post">
<table border = "1" align = "center" bordercolor = "blue">
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Cedula*</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtcedula" value = "<? echo $filas["cedula"]; ?>" readonly maxlength style="font-family: Arial Black; color: #0080FF; border-style: double; border-width: 3px; background-color: #ffffff" setfocus></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Fecha*</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtfecha" value = "<? echo $filas ["fecha"]; ?>" maxlength style="font-family: Arial Black; color: #0080FF; border-style: double; border-width: 3px; background-color: #ffffff"></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Nombre *</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtnombre" value = "<? echo $filas ["nombre"]; ?>" maxlength style="font-family: Arial Black; color: #0080FF; border-style: double; border-width: 3px; background-color: #ffffff"></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Escuadron</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input name = "txtescuadron" type = "text" style="font-family: Arial Black; color: #0080FF; border-style: double; border-width: 3px; background-color: #ffffff" value = "<? echo $filas ["escuadron"] ?>" maxlength></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Año</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtano" value = "<? echo $filas ["ano"] ?>" maxlength style="font-family: Arial Black; color: #0080FF; border-style: double; border-width: 3px; background-color: #ffffff"></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Mes*</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtmes" value = "<? echo $filas ["mes"]; ?>" maxlength style="font-family: Arial Black; color: #0080FF ; border-style: double; border-width: 3px; background-color: #ffffff"></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Semana *</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtsemana" value = "<? echo $filas ["semana"]; ?>" maxlength style="font-family: Arial Black; color:
#0080FF
; border-style: double; border-width: 3px; background-color: #ffffff"></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Dia*</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtdia" value = "<? echo $filas ["dia"]; ?>" maxlength style="font-family: Arial Black; color:
#0080FF
; border-style: double; border-width: 3px; background-color:
#FFFFFF"></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Valor *</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtvalor" value = "<? echo $filas ["valor"]; ?>" maxlength style="font-family: Arial Black; color:
#0080FF
; border-style: double; border-width: 3px; background-color:
#FFFFFF"></td>
</tr>
<tr>
<td> <center>
<label>
<input type="submit" name="button" id="button" value="Enviar">
</label>
</center> </td>
<td bgcolor="#FFFFFF"> <center>
<label>
<input type="reset" name="button2" id="button2" value="Restablecer">
</label>
</center> </td>
</tr>
<?
} //mq
} //else
?>
</table><input type="hidden" name = "txtid" value="<? echo $numfilas["id"]; ?>">
</form>
y este codigo es que me esta guardando mal la modificacion por que cuando una cedula tiene dos registro, el codigo anterior me trae dos tablas con dos registros, y cuando modifico un solo registro el codigo inmediatamente me lo guarda a todos los otros registros osea que un solo registro queda repetido varias veces
<?php
$txtcedula=$_REQUEST['txtcedula'];
$txtfecha=$_REQUEST['txtfecha'];
$txtnombre=$_REQUEST['txtnombre'];
$txtescuadron=$_REQUEST['txtescuadron'];
$txtano=$_REQUEST['txtano'];
$txtmes=$_REQUEST['txtmes'];
$txtsemana=$_REQUEST['txtsemana'];
$txtdia=$_REQUEST['txtdia'];
$txtvalor=$_REQUEST['txtvalor'];
$cn=mysql_connect("localhost","root","")or die ("no se puede establecer la conexion");
mysql_select_db("sisbagir");
$consulta = "select * from ensayo where cedula= '$txtcedula'";
$resultado = mysql_query($consulta);
$numreg = mysql_num_rows($resultado);
if($numreg == 0)
{
echo "No existen registros";
}
else
{
$consulta = "update ensayo set fecha = '$txtfecha', nombre = '$txtnombre', escuadron = '$txtescuadron', ano = '$txtano', mes= '$txtmes', semana='$txtsemana', dia='$txtdia', valor='$txtvalor' where cedula = '$txtcedula'";
$resultado = mysql_query($consulta);
echo "<br><br><br><br>";
echo "<center>Registro modificado</center>";
}
?>
este codigo me busca el dato a modificar y me lo trae a una tabla
<?
$txtmodificar=$_REQUEST['txtmodificar'];
$cn=mysql_connect("localhost","root","")or die ("no se puede establecer la conexion");
mysql_select_db("sisbagir");;
$consulta = "select * from ensayo where cedula = '$txtmodificar'";
$resultado = mysql_query($consulta);
$numreg = mysql_num_rows($resultado);
if($numreg == 0)
{
echo "No existen registros";
}
else
{
while($filas = mysql_fetch_array($resultado))
{
?>
</font>
<center> <font size = "5" color = "#FFFFFF" face = "arial black" class = "blur"> Modificar </font>
</center>
<form action = "modificar.php" method = "post">
<table border = "1" align = "center" bordercolor = "blue">
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Cedula*</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtcedula" value = "<? echo $filas["cedula"]; ?>" readonly maxlength style="font-family: Arial Black; color: #0080FF; border-style: double; border-width: 3px; background-color: #ffffff" setfocus></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Fecha*</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtfecha" value = "<? echo $filas ["fecha"]; ?>" maxlength style="font-family: Arial Black; color: #0080FF; border-style: double; border-width: 3px; background-color: #ffffff"></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Nombre *</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtnombre" value = "<? echo $filas ["nombre"]; ?>" maxlength style="font-family: Arial Black; color: #0080FF; border-style: double; border-width: 3px; background-color: #ffffff"></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Escuadron</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input name = "txtescuadron" type = "text" style="font-family: Arial Black; color: #0080FF; border-style: double; border-width: 3px; background-color: #ffffff" value = "<? echo $filas ["escuadron"] ?>" maxlength></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Año</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtano" value = "<? echo $filas ["ano"] ?>" maxlength style="font-family: Arial Black; color: #0080FF; border-style: double; border-width: 3px; background-color: #ffffff"></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Mes*</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtmes" value = "<? echo $filas ["mes"]; ?>" maxlength style="font-family: Arial Black; color: #0080FF ; border-style: double; border-width: 3px; background-color: #ffffff"></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Semana *</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtsemana" value = "<? echo $filas ["semana"]; ?>" maxlength style="font-family: Arial Black; color:
#0080FF
; border-style: double; border-width: 3px; background-color: #ffffff"></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Dia*</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtdia" value = "<? echo $filas ["dia"]; ?>" maxlength style="font-family: Arial Black; color:
#0080FF
; border-style: double; border-width: 3px; background-color:
#FFFFFF"></td>
</tr>
<tr>
<td><div align="right"><font face="Georgia, Times New Roman, Times, serif"><strong><font size = "2" color = "#FFFFFF">Valor *</font></strong></font></div></td>
<td bgcolor="#FFFFFF"><input type = "text" name = "txtvalor" value = "<? echo $filas ["valor"]; ?>" maxlength style="font-family: Arial Black; color:
#0080FF
; border-style: double; border-width: 3px; background-color:
#FFFFFF"></td>
</tr>
<tr>
<td> <center>
<label>
<input type="submit" name="button" id="button" value="Enviar">
</label>
</center> </td>
<td bgcolor="#FFFFFF"> <center>
<label>
<input type="reset" name="button2" id="button2" value="Restablecer">
</label>
</center> </td>
</tr>
<?
} //mq
} //else
?>
</table><input type="hidden" name = "txtid" value="<? echo $numfilas["id"]; ?>">
</form>
y este codigo es que me esta guardando mal la modificacion por que cuando una cedula tiene dos registro, el codigo anterior me trae dos tablas con dos registros, y cuando modifico un solo registro el codigo inmediatamente me lo guarda a todos los otros registros osea que un solo registro queda repetido varias veces
<?php
$txtcedula=$_REQUEST['txtcedula'];
$txtfecha=$_REQUEST['txtfecha'];
$txtnombre=$_REQUEST['txtnombre'];
$txtescuadron=$_REQUEST['txtescuadron'];
$txtano=$_REQUEST['txtano'];
$txtmes=$_REQUEST['txtmes'];
$txtsemana=$_REQUEST['txtsemana'];
$txtdia=$_REQUEST['txtdia'];
$txtvalor=$_REQUEST['txtvalor'];
$cn=mysql_connect("localhost","root","")or die ("no se puede establecer la conexion");
mysql_select_db("sisbagir");
$consulta = "select * from ensayo where cedula= '$txtcedula'";
$resultado = mysql_query($consulta);
$numreg = mysql_num_rows($resultado);
if($numreg == 0)
{
echo "No existen registros";
}
else
{
$consulta = "update ensayo set fecha = '$txtfecha', nombre = '$txtnombre', escuadron = '$txtescuadron', ano = '$txtano', mes= '$txtmes', semana='$txtsemana', dia='$txtdia', valor='$txtvalor' where cedula = '$txtcedula'";
$resultado = mysql_query($consulta);
echo "<br><br><br><br>";
echo "<center>Registro modificado</center>";
}
?>
Valora esta pregunta
0