domingo, 20 de abril de 2014

Creación Pagina PHP


Creación Pagina PHP


Se crean tres paginas así: 

Conectar: 

Se crea la pagina php, "conectar.php", con el fin de realizar la conexión con la Base de Datos así: 

<?php 
$activacion = $_GET['activacion'];
$dia = date('d');
$mes = date('m');
$anio = date('Y');
$hora = date('h');
$minuto = date('i');
$segundo = date('s');

$conexion = mysql_connect("localhost", "php", "123");
mysql_select_db("alarma",$conexion);
$sql = "INSERT INTO `datos`(`id`, `dia`, `mes`, `anio`, `hora`, `minuto`, `segundo`, `activacion`) VALUES 
       (NULL,'$dia','$mes','$anio','$hora','$minuto','$segundo','$activacion')";
$res = mysql_query($sql, $conexion) or die ("Error en la consulta"); 
?>

Insertar: 

Se crea la Pagina php, "insertar.php", con el fin de probar la pagina y la inserción a la Base de Datos así: 
<html>
<head>
<title></title>
</head>
<body>
<form action = "conectar.php" method = "GET"><br><br>
Dia: <input type = "text" name = txtDia><br>
Mes: <input type = "text" name = txtMes><br>
Anio: <input type = "text" name = txtAnio><br>
Hora: <input type = "text" name = txtHora><br>
Minuto: <input type = "text" name = txtMinuto><br>
Segundo: <input type = "text" name = txtSegundo><br>
<input type = "submit" value = "Ok">
</body>
</html>

Mostrar: 

Se crea la pagina "mostrar.php", con el fin de mostrar los datos que se insertan en la Base de Datos así: 

<?php
$conexion = mysql_connect("localhost", "php", "123");
mysql_select_db("alarma",$conexion);
$sql = "SELECT * FROM `datos`";
$res = mysql_query($sql, $conexion) or die ("Error en la consulta");
$total = mysql_num_rows($res);
if ($total > 0)
{
echo "<table border = 1 align = center>"
."<tr>\n"
."<th>id</th>\n"
."<th>Dia</th>\n"
."<th>Mes</th>\n"
."<th>Anio</th>\n"
."<th>Hora</th>\n"
."<th>Minuto</th>\n"
."<th>Segundo</th>\n"
."<th>Activacion</th>\n"
."</tr>\n";

while($reg = mysql_fetch_array($res))
{
print "<td>".$reg['id']."</td>";
print "<td>".$reg['dia']."</td>";
print "<td>".$reg['mes']."</td>";
print "<td>".$reg['anio']."</td>";
print "<td>".$reg['hora']."</td>";
print "<td>".$reg['minuto']."</td>";
print "<td>".$reg['segundo']."</td>";
print "<td>".$reg['activacion']."</td>";
print "</tr>";
}
}
?>
.