
25/07/2014, 17:12
|
| | Fecha de Ingreso: junio-2013
Mensajes: 68
Antigüedad: 11 años, 8 meses Puntos: 1 | |
Respuesta: Fechas con PHP Y MYSQL Les dejo el codigo Cita: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
</head>
<body>
<?PHP
error_reporting(0);
//OBTENGO VALORES INTRODUCIDOS EN EL FORMULARIO
$insertar = $_REQUEST['insertar'];
$fecha_inicio = $_REQUEST['fecha_inicio'];
$fecha_termino = $_REQUEST['fecha_termino']; $query = mysql_result("select DATEDIFF(" . $fecha_termino . ", " . $fecha_inicio . ")");
if (isset($insertar) && $error==false)
{
//INSERTO DATOS EN BD
$conexion = mysql_connect ("localhost", "root", "password")
or die ("No se puede conectar con el servidor");
mysql_select_db ("fecha")
or die ("No se puede seleccionar la base de datos");
$instruccion = "insert into tabla (fecha_inicio, fecha_termino, dias )
values ('$fecha_inicio', '$fecha_termino', '$query')";
mysql_query ($instruccion, $conexion) or die (mysql_error());
mysql_close($conexion);
// mostrar datos
print ("<br>\n");
print ("<center><H1>\nMuestro resultados</font></H1>\n");
print (" <LI>Fecha de Inicio:" . $fecha_inicio . "</strong>\n");
print (" <LI>Diferencia de fechas=" . $query . "</strong>\n");
}
else
{
//FORMULARIO DONDE OBTENGO LAS FECHAS
?>
<FORM CLASS="borde" ACTION="dem.php" NAME="fcalen" METHOD="POST"
ENCTYPE="multipart/form-data">
<?php
if (isset($_POST));
?>
<!-- fecha_inicio-->
Fecha de Inicio:</br>
<INPUT TYPE="TEXT" NAME="fecha_inicio" SIZE="8" MAXLENGTH="70"
<?PHP
if (isset ($insertar))
print ("VALUE='$fecha_inicio'>\n");
?>></br>
<!-- fecha_termino-->
Fecha termino:</br>
<INPUT TYPE="TEXT" NAME="fecha_termino" SIZE="8" MAXLENGTH="70"
<?PHP
if (isset ($insertar))
print ("VALUE='$fecha_termino'>\n");
?>></br>
<input type="submit" name="insertar" value="Insertar fechas" >
<?php
}
?>
</body>
</html> |