Ver Mensaje Individual
  #3 (permalink)  
Antiguo 24/11/2008, 22:11
Makoto
 
Fecha de Ingreso: octubre-2008
Ubicación: Temuco
Mensajes: 24
Antigüedad: 15 años, 7 meses
Puntos: 0
Sonrisa Respuesta: Editar en MySQL y PHP

Oh, gracias por responder disculpa no me había metido al Foro en unos 2 días y pille el post en la quinta página.

La cosa es que todavia no puedo solucionar mi problema, en un rato más edito el post y pongo con imagenes lo que quiero hacer.

Código PHP:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Editar</title>
</head>

<body>
<form name="form2" method="POST" action="">
  Haga clic aquí para encontrar campos en su base de datos.<br><br><input name="Buscar" type="submit" id="Buscar" value="Buscar">
  <br><br>
  <table width="450"  border="1" cellspacing="0" cellpadding="0">
    <tr>
      <td align="center" width="50">Id</td>
      <td width="75">Nombre</td>
      <td width="275">Descripción</td>
      <td align="center" width="50">¿Editar?</td>
    </tr>
<?
// Conexión a la base de datos.
include 'Conexion.php';
$link Conexion();

if (isset(
$_REQUEST['Buscar']))
{
// Instrucción
$Sql "SELECT * FROM Campos";
$Query mysql_query ($Sql$link) or die ("Fallo en la consulta, razón: "."<strong>"mysql_error() ."</strong>");

// Recorriendo la tabla artculos
$nfilas mysql_num_rows ($Query);
if (
$nfilas 0)
// if
for ($i=0$i<$nfilas$i++)
// for
$fila mysql_fetch_array($Query);

print (
"<tr>");
print (
"<td>"$fila['Id'] . "</td>");
print (
"<td>"$fila['Nombre'] . "</td>");
print (
"<td>"$fila['Descripcion'] . "</td>");
print (
"<td align=\"center\"><a href=\"?id=".$fila['Id']."\"><img src=\"Lupa.jpg\" width=\"24px\" height=\"24px\"\></a></td>");
print (
"</tr>");
// Fin for
// Fin if
else
{
print (
"No hay artículos disponibles por el momento, pronto tendrá nuevas noticias!");
}
}
?>
  </table>
</form>
<?
// Después del POST
if ($_GET[Editar])
 {
 
$Id $_GET[Editar];
 
$Nombre $_GET['Nombre'];
 
$Descripcion $_GET['Descripcion'];
 
 
$Sql "UPDATE Campos SET Nombre='$Nombre', Descripcion='$Descripcion' WHERE Id='$Id'";
 
$Query mysql_query ($Sql$link) or die ("Fallo: <b>" mysql_error() . "</b>");
 
 echo (
"Campos editados");
 
 
mysql_close($link);
 }
else
 {
?>
<form name="form1" method="GET" action="">
  <table width="400"  border="1" cellspacing="0" cellpadding="0">
    <?
    
if ($_GET[id])
    {
    
$Id $_GET['id'];
    
    
// Instrucción
    
$Sql "SELECT * FROM Campos WHERE Id = '$Id'";
    
$Query mysql_query ($Sql$link) or die ("Fallo en la consulta, razón: "."<strong>"mysql_error() ."</strong>");
    
    
// Recorriendo la tabla artculos
    
$nfilas mysql_num_rows ($Query);
    if (
$nfilas 0)
    { 
// if
    
for ($i=0$i<$nfilas$i++)
    { 
// for
    
$fila mysql_fetch_array($Query);

    print (
"<tr>");
    print (
"<td>Id:</td>");
    print (
"<td><b>$Id</b></td>");
    print (
"</tr>");
    print (
"<tr>");
    print (
"<td>Nombre:</td>");
    print (
"<td><input name=\"Nombre\" type=\"text\" id=\"Nombre\" value=\"".$fila['Nombre']."\"></td>");
    print (
"</tr>");
    print (
"<tr>");
    print (
"<td>Descripción:</td>");
    print (
"<td><textarea name=\"Descripcion\" cols=\"35\" id=\"Descripcion\">"$fila['Descripcion'] ."</textarea></td>");
    print (
"</tr>");
    print (
"<tr>");
    print (
"<td>&nbsp;</td>");
    print (
"<td><a href=\"?Editar=".$fila['Id']."\"><img src=\"Editar.gif\" width=\"24px\" height=\"24px\"\></a></td>");
    print (
"</tr>");
    } 
// Fin for
    
// Fin if
    
else
    print (
"No hay artículos disponibles por el momento, pronto tendrá nuevas noticias!");
    }
    
?>
  </table>
</form>
<?
 
}
?>
<p><a href="Edit.php">Recargar</a></p>
<p><a href="Index.HTML">Index.HTML</a></p>
</body>
</html>
Es algo así la cosa pero cuando quiero editar, edita el puro Id y nada más.

Ojala me puedan ayudar gracias.

EDITO: ya lo resolví.

Última edición por Makoto; 25/11/2008 a las 22:25 Razón: POST resuelto.