Tema: Editar Tabla
Ver Mensaje Individual
  #5 (permalink)  
Antiguo 30/08/2009, 12:20
softdeveloper
 
Fecha de Ingreso: agosto-2009
Mensajes: 3
Antigüedad: 14 años, 8 meses
Puntos: 0
Respuesta: Editar Tabla

Cita:
Iniciado por abimaelrc Ver Mensaje
Lo mejor es que vayas ingresando lo que has hecho y te vamos indicando que debes arreglar
saludos amigo esto es lo que he hecho:

--------------------------------------------------------------------------------------------------------
pagina.php

esta pagina es la tabla que muestra los datos de las base de datos y en esta tabla se incluyen los enlaces para editar/eliminar los datos.

<?php

include("config.php");
// connect to database
$connect=mysql_connect("$dbHost","$dbUser","$dbPas s");

// select database
mysql_select_db("$dbDatabase",$connect);

// mysql query

$query=mysql_query("SELECT nombre,email FROM alumnos",$connect);

while($consulta=mysql_fetch_array($query)){
?>

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>OPCIONES</title>
</head>

<body>

<div align="center">
<table cellpadding="0" cellspacing="0" width="604" height="118" border="1">
<!-- MSTableType="layout" -->
<tr>
<td bgcolor="#FF0000" align="center"><b>
<font face="Arial" size="2" color="#FFFFFF">OPCIONES</font></b></td>
<td bgcolor="#FF0000" align="center"><b>
<font face="Arial" size="2" color="#FFFFFF">NOMBRE</font></b></td>
<td height="61" bgcolor="#FF0000" align="center"><b>
<font face="Arial" size="2" color="#FFFFFF">EMAIL</font></b></td>
</tr>
<tr>
<td width="92" valign="top" align="center">
<font size="1" face="Arial"><font color="#0066FF">&nbsp;</font><a href="edit.php?id="><font color="#0066FF">Editar
</font></a></font><font size="1" face="Times New Roman">
<font color="#0066FF">׀ </font>
<a href="file:///C:/Documents%20and%20Settings/Administrador/Mis%20documentos/Mis%20Webs/remove.php">
<font color="#0066FF">Eliminar</font></a></font></td>
<td width="305" align="center">
<font face="Arial" size="1"><? echo $consulta['nombre'] ?></font></td>
<td width="199" height="55" align="center">
<font face="Arial" size="1"><? echo $consulta['email'] ?></font></td>
</tr>
</table>
</div>

</body>

</html>
<?
// this end while
}
// close db connection
mysql_close($connect);

?>
--------------------------------------------------------------------------------------------------------
edit.php

este es el formulario que sirve para editar editar los datos de la bd, al hacer click en el enlace editar se mostrara esta pagina y editara los datos solicitados.

<?php

include("config.php");

// connect to database
$connect=mysql_connect('$dbHost','$dbUser','$dbPas s');

// select the database
mysql_select_db('$dbDatabase',$connect);

// mysql queries

$id = $_GET["id"];
$s = "SELECT * FROM alumnos WHERE id = '".mysql_real_escape_string($id)."'";
$r = mysql_query($s) or die(mysql_error());
$row = mysql_fetch_assoc($r);
//con $row llamas todas las columnas que quieres que editen dentro de los input

?>
<form method="POST" action="updatedata.php">
<div align="center">
<center>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-width: 0" bordercolor="#111111" width="157" height="150" id="AutoNumber1">
<tr>
<td width="66" height="38" style="border-style: none; border-width: medium">
Nombre:</td>
<td width="85" height="38" style="border-style: none; border-width: medium">
<input type="text" name="nombrenew" size="20" value="<?php echo $row['nombre'] ?>"><input type="hidden" name="nombreold" size="20" value="<?php echo $row['nombre'] ?>"></td>
</tr>
<tr>
<td width="66" height="38" style="border-style: none; border-width: medium">
Email:</td>
<td width="85" height="38" style="border-style: none; border-width: medium">
<input type="text" name="emailnew" size="20" value="<?php echo $row['email'] ?>"><input type="hidden" name="emailold" size="20" value="<?php echo $row['email'] ?>"></td>
</tr>
<tr>
<td width="66" height="37" style="border-style: none; border-width: medium">
Sexo:</td>
<td width="85" height="37" style="border-style: none; border-width: medium">
<input type="text" name="sexonew" size="20" value="<?php echo $row['sexo'] ?>"><input type="hidden" name="sexoold" size="20" value="<?php echo $row['sexo'] ?>"></td>
</tr>
<tr>
<td width="157" height="37" colspan="2" style="border-style: none; border-width: medium">
<p align="center"><input type="submit" value="Enviar" name="B1"></td>
</tr>
</table>
</center>
</div>
</form>

<?

// mysql close

mysql_close($connect);

?>
--------------------------------------------------------------------------------------------------------
config.php

// estas son las variables que se usan para conectarse a la base de datos

<?php
// information
$dbHost = "localhost";
$dbUser = "root";
$dbPass = "password";
$dbDatabase = "bd_escuela";

?>
--------------------------------------------------------------------------------------------------------
bd_escuela

esta es la base de datos con sus tablas y datos

debe crearse primero la base de datos con el nombre
de bd_escuela y despues ejecutar el siguiente codigo
sql:

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `alumnos`
--

CREATE TABLE `alumnos` (
`id` mediumint(9) NOT NULL auto_increment,
`nombre` varchar(80) default NULL,
`email` varchar(98) default NULL,
`sexo` varchar(10) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ;

--
-- Volcar la base de datos para la tabla `alumnos`
--

INSERT INTO `alumnos` VALUES (12, 'melissa', '[email protected]', 'Mujer');
INSERT INTO `alumnos` VALUES (9, 'hugo', '[email protected]', 'Hombre');
INSERT INTO `alumnos` VALUES (8, 'fernando', '[email protected]', 'hombre');
INSERT INTO `alumnos` VALUES (13, 'gabriela', '[email protected]', 'Mujer');
INSERT INTO `alumnos` VALUES (18, 'fernando ignacio', '[email protected]', 'Hombre');