Ver Mensaje Individual
  #3 (permalink)  
Antiguo 06/02/2011, 16:45
Avatar de camilo1012
camilo1012
 
Fecha de Ingreso: febrero-2011
Mensajes: 46
Antigüedad: 14 años
Puntos: 1
Respuesta: Panel de Administración con MySQL

Con PHP todo es posible, tengo unos códigos que te puede ser muy útiles, uno para insertar, otro para modificar, borrar y una lectura de tabla, lo malo que todos son archivos independiente, pero si le dedicas tiempo podrás logar lo que quieres.

El primero es insertar.html, con el puedes insertar atravez de un formulario, luego pasa al insertar.php

insertar.html
Código:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>insertar.html</title>
</head>
<body>
<div align="center">
<h1>Insertar un registro</h1>
<br>
<form method="post" action="insertar.php">
Id<br>
<input type="text" name="id"><br>
Nombre<br>
<input type="text" name="nombre"><br>
Direccion<br>
<input type="text" name="direccion"><br>
<input type="submit" value="Insertar">
</form>
</div>
</body>
</html>
insertar.php
Código:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>insertar.php</title>
</head>

<body>
<?
mysql_connect("127.0.0.1","user","pass");
mysql_db_query("Tu_base","insert into tu_tabla (nombre,telefono) values ('$nombre','$telefono')");
?>
<h1><div align="center">Registro Insertado</div></h1>
<div align="center"><a href="lectura.php">Visualizar el contenido de la Base</a></div>
</body>
</html>

Luego pasa a la lectura de la tabla con lectura.php

lectura.php
Código:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>lectura.php</title>
</head>

<body>
<h1><div align="center">Lectura de la tabla</div></h1>
<br>
<br>
<?
mysql_connect("127.0.0.1","user","pass");
$result=mysql_db_query("tu_base","select * from tu_tabla");
?>
<table align="center">
<tr>
<th>Nombre</th>
<th>Telefono</th>
</tr>
<?
while ($row=mysql_fetch_array($result))
{
	echo '<tr><td>'.$row["nombre"].'</td>';
	echo '<td>'.$row["telefono"].'</td></tr>';
}
mysql_free_result($result)
?>
</table>
<div align="center">
<a href="insertar.html">Anadir un nuevo registro</a><br>
<a href="actualizar1.php">Actualizar un registro exitente</a><br>
<a href="borrar1.php">Borrar un registro</a><br>
</div>
</body>
</html>
Ahora el formulario para borrar:

borrar1.php
Código:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>borrar1.php</title>
</head>

<body>
<div align="center">
<h1>Borrar un registro</h1>
<br>

<?
mysql_connect("127.0.0.1","user","pass");
echo '<form method="post" action="borrar2.php">Nombre<br>';

$sSQL="Select nombre From clientes Order By nombre";
$result=mysql_db_query("ejemplo",$sSQL);

echo '<select name="nombre">';

while ($row=mysql_fetch_array($result))
{echo '<option>'.$row["nombre"];}
mysql_free_result($result)
?>
</select>
<br>
<input type="submit" value="Borrar">
</form>
</div>

</body>
</html>

borrar2.php
Código:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>actualizar2.php</title>
</head>

<body>
<?
mysql_connect("127.0.0.1","user","pass");
$sSQL="Update clientes Set telefono='$telefono' Where nombre='nombre'";
mysql_db_query("ejemplo",$sSQL);
?>
<h1><div align="center">Registro Actualizado</div></h1>
<div align="center"><a href="lectura.php">Visualizar el contenido de la Base</a></div>

</body>
</html>
y por ultimo, actualizar los registros:

actualizar1.php
Código:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>actualizar1.php</title>
</head>

<body>
<div align="center">
<h1>Actualizar un registro</h1>
<?
mysql_connect("127.0.0.1","user","pass");
echo '<form method="post" action="actualizar2.php">Nombre<br>';
$sSQL="Select nombre From clientes Order By nombre";
$result=mysql_db_query("ejemplo",$sSQL);

echo '<select name="nombre">';

while ($row=mysql_fetch_array($result))
{echo '<option>'.$row["nombre"];}
?>
</select>
<br>
Telefono<br>
<input type="text" name="telefono"><br>
<input type="submit" value="Actualizar">
</form>
</div>
</body>
</html>
actualizar2.php
Código:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>actualizar2.php</title>
</head>

<body>
<?
mysql_connect("127.0.0.1","user","pass");
$sSQL="Update clientes Set telefono='$telefono' Where nombre='nombre'";
mysql_db_query("ejemplo",$sSQL);
?>
<h1><div align="center">Registro Actualizado</div></h1>
<div align="center"><a href="lectura.php">Visualizar el contenido de la Base</a></div>

</body>
</html>

Espero que te sirva