conexion.php
Código PHP:
<?
$dbhost="mysql1.000webhost.com"; // host del MySQL (generalmente localhost)
$dblogin="admin"; // aqui debes ingresar el nombre de usuario
// para acceder a la base
$dbpassword="11111111"; // password de acceso para el usuario de la
// linea anterior
$db="webpost"; // Seleccionamos la base con la cual trabajar
$conexion = mysql_connect($dbhost, $dblogin, $dbpassword);
mysql_select_db($db, $conexion);
?>
cerrar_conex.php
Código PHP:
<?
mysql_close($conexion);
?>
Código PHP:
<?
include ("conexion.php");
if (!isset($_GET[accion]) OR $_GET[accion] == ""){
//!isset($accion)){
echo"
<html>
<head><title>Guardar datos en la base</title></head>
<body>
<h3>Guardar datos en la base</h3>
<form name=\"form1\" method=\"post\"
action=\"guardar.php?accion=guardar\">
<p>Nombre:<br>
<input type=\"text\" name=\"titulo\">
</p>
<p>Apellido:<br>
<input type=\"text\" name=\"contenido\">
</p>
<p>DNI:<br>
<input type=\"text\" name=\"fecha\" readonly=\"1\" value='". date("d") . "/" . date("m") . "/" . date("Y") ."'>
</p>
<p>
<input type=\"submit\" name=\"Submit\" value=\"Guardar Datos\">
</p>
</form>
</body>
</html>";
}
elseif($accion=="guardar"){
include ("conexion.php");
$result = mysql_query("INSERT INTO gb (idpost, titulo, fechareg, contenido) VALUES ('',$titulo,$contenido,$fecha)",$conexion) or die(mysql_error() );
echo" <html>
<head></head>
<body>
<h3>Los datos han sido guardados</h3>
</body>
</html>";
}
include ("cerrar_conex.php");
?>
ver.php
Código PHP:
<?
include "conexion.php";
$result=mysql_query("SELECT * FROM gb ORDER BY fechareg", $conexion);
echo"<table width=300 border='1'>
<tr>
<td><b>Nombre</b></td><td><b>Apellido</b></td><td><b>DNI</b></td>
</tr>";
while($row=mysql_fetch_row($result)){
echo"<tr>
<td>$row[1]</td><td>$row[2]</td><td>$row[3]
<a href=\"actualizar.php?id=$row[0]\">Actualizar</a></td>
</tr>";
}
echo"</table>";
include ("cerrar_conex.php");
?>
actualizar.php
Código PHP:
<?
include ("conexion.php");
/* if (!isset($_GET[id]) OR $_GET[id] == ""){
echo "Se necesita un id";
}
else{ */
if (!isset($_GET[accion]) OR $_GET[accion] == ""){
//!isset($accion)){
$result=mysql_query("SELECT * FROM gb WHERE idpost=".$_GET['id'], $conexion);
$row=mysql_fetch_row($result);
echo"<html>
<head><title>Actualizar datos de la base</title></head>
<body>
<form action=\"actualizar.php?accion=guardar\" method=\"POST\">
Nombre:<br>
<input type=\"hidden\" name=\"id\" value='".$row[0]."'>
<input type=\"text\" value='".$row[1]."' name=\"titulo\"><br>
Apellido:<br>
<input type=\"text\" value='".$row[2]."' name=\"fecha\"><br>
DNI:<br>
<input type=\"text\" value='".$row[3]."' name=\"fecha\"><br>
<input type=\"submit\" value=\"Guardar\">
</form>
</body>
</html>";
}elseif($accion==guardar){
include ("conexion.php");
$result=mysql_query("UPDATE gb SET titulo=$titulo, contenido=$contenido, fechareg=$fecha WHERE idpost=".$_POST['id'],$conexion);
echo"
<html>
<body>
<h3>Los registros han sido actualizados</h3>
</body>
</html>";
}
include ("cerrar_conex.php");
?>
gracias de ante mano