Foros del Web » Programando para Internet » PHP »

Problemas con fecha en el formulario

Estas en el tema de Problemas con fecha en el formulario en el foro de PHP en Foros del Web. Estimados amigos. Trabajo con Dreamweaver 8 y Wampserver (Apache, Mysql, PHP) Tengo una tabla cuyos datos se completan desde un formulario. En la tabla tengo ...
  #1 (permalink)  
Antiguo 04/10/2008, 02:35
 
Fecha de Ingreso: septiembre-2007
Mensajes: 50
Antigüedad: 16 años, 7 meses
Puntos: 0
Problemas con fecha en el formulario

Estimados amigos.

Trabajo con Dreamweaver 8 y Wampserver (Apache, Mysql, PHP)

Tengo una tabla cuyos datos se completan desde un formulario.
En la tabla tengo un campo que se llama FECHA con el tipo DATE

Quiero que al cargar los datos de ese cliente me figure la fecha en la que ha rellenado el formulario de la forma 15 – 05 – 08 (día, mes, año).

En estos momentos al cargar la página con los datos de cualquier cliente, en la fecha sólo me salen ceros y de esta forma: 0000 – 00 – 00 (año, mes, día).

Así que lo que quiero es que se figure la fecha de entrada de datos (Fecha en la que se ha rellenado el formulario) y cambiar el formato actual.

El código de la página dónde deben figurar esos datos es:


<?php require_once('Connections/conexionconsultas.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_ver = 20;
$pageNum_ver = 0;
if (isset($_GET['pageNum_ver'])) {
$pageNum_ver = $_GET['pageNum_ver'];
}
$startRow_ver = $pageNum_ver * $maxRows_ver;

mysql_select_db($database_conexionconsultas, $conexionconsultas);
$query_ver = "SELECT * FROM `general`";
$query_limit_ver = sprintf("%s LIMIT %d, %d", $query_ver, $startRow_ver, $maxRows_ver);
$ver = mysql_query($query_limit_ver, $conexionconsultas) or die(mysql_error());
$row_ver = mysql_fetch_assoc($ver);

if (isset($_GET['totalRows_ver'])) {
$totalRows_ver = $_GET['totalRows_ver'];
} else {
$all_ver = mysql_query($query_ver);
$totalRows_ver = mysql_num_rows($all_ver);
}
$totalPages_ver = ceil($totalRows_ver/$maxRows_ver)-1;

$queryString_ver = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_ver") == false &&
stristr($param, "totalRows_ver") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_ver = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_ver = sprintf("&totalRows_ver=%d%s", $totalRows_ver, $queryString_ver);
?><!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&iacute;tulo</title>
</head>

<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="760" align="center">
<tr>
<th width="120" scope="col">fecha</th>
<th width="333" scope="col">reforma</th>
<th width="181" scope="col">localidad</th>
<th width="106" scope="col">provincia</th>
</tr>
<?php do { ?>

<tr>

<td><div align="center"><?php echo $row_ver['Fecha']; ?></div></td>

<td><div align="center"><a href="datos_cliente.php?Id=<?php echo $row_ver['Id']; ?>" target="_blank"><?php echo $row_ver['reforma']; ?></a></div></td>
<td><div align="center"><a href="datos_cliente.php?Id=<?php echo $row_ver['Id']; ?>" target="_blank"><?php echo $row_ver['Localidad']; ?></a></div></td>
<td><div align="center"><a href="datos_cliente.php?Id=<?php echo $row_ver['Id']; ?>" target="_blank"><?php echo $row_ver['Provincia']; ?></a></div></td>
</tr>
<?php } while ($row_ver = mysql_fetch_assoc($ver)); ?>
</table>
<br />
<table width="760">
<tr>
<td width="78"><?php if ($pageNum_ver > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_ver=%d%s", $currentPage, max(0, $pageNum_ver - 1), $queryString_ver); ?>" target="_blank">Anterior</a>
<?php } // Show if not first page ?> </td>
<td width="589">&nbsp;</td>
<td width="77"><?php if ($pageNum_ver < $totalPages_ver) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_ver=%d%s", $currentPage, min($totalPages_ver, $pageNum_ver + 1), $queryString_ver); ?>" target="_blank">Siguiente</a>
<?php } // Show if not last page ?> </td>
</tr>
</table>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($ver);
?>


Espero vuestras respuestas.


Saludos.
  #2 (permalink)  
Antiguo 05/10/2008, 09:41
Avatar de juaniquillo
Colaborador
 
Fecha de Ingreso: noviembre-2005
Ubicación: San Juan, Puerto Rico
Mensajes: 5.745
Antigüedad: 18 años, 5 meses
Puntos: 281
Respuesta: Problemas con fecha en el formulario

necesitas insertar la fecha cuando haces el insert a la base de datos. La fecha no se pone sola. Lo que usualmente se usa es la función NOW() dellenguaje SQL, pero puedes usar la función date() de PHP. Lo que necesitas poner es la página donde tienes el formulario y haces el insert, no donde muestras la información.
__________________
Por fin.. tengo algo parecido a un blog
Y por lo visto ya estoy escribiendo...
  #3 (permalink)  
Antiguo 06/10/2008, 01:32
 
Fecha de Ingreso: septiembre-2007
Mensajes: 50
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Problemas con fecha en el formulario

Estimado Juaniquillo.

No tengo ni idea ni de PHP, ni de SQL.
Te envío el código de la página del formulario y si me indicas el código que debo poner y el lugar, te estaría muy agradecido.

Como datos te puedo decir que la TABLA se llama general

Tiene un campo que se llama fecha con el tipo DATE, que es el campo dónde debe incluirse la fecha del formulario.

La fecha la quiero en formato día(00) - mes(00) - año(0000)

El código de la página es:


<?php require_once('Connections/conexionreformas.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO general (`Nombre_ y _Apellidos`, Dirección, Teléfono, Email, `Plazo_ de_ inicio`, Localidad, Provincia, `Código_ postal`, Descripción, reforma) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Nombre_y_Apellidos'], "text"),
GetSQLValueString($_POST['Direccin'], "text"),
GetSQLValueString($_POST['Telfono'], "text"),
GetSQLValueString($_POST['Email'], "text"),
GetSQLValueString($_POST['Plazo_de_inicio'], "text"),
GetSQLValueString($_POST['Localidad'], "text"),
GetSQLValueString($_POST['Provincia'], "text"),
GetSQLValueString($_POST['Cdigo_postal'], "text"),
GetSQLValueString($_POST['Descripcin'], "text"),
GetSQLValueString($_POST['obra_realizar'], "text"));

mysql_select_db($database_conexionreformas, $conexionreformas);
$Result1 = mysql_query($insertSQL, $conexionreformas) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?><!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&iacute;tulo</title>
</head>

<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td width="232" align="right" nowrap>Nombre y Apellidos:</td>
<td> <div align="center">
<input type="text" name="Nombre_y_Apellidos" value="" size="40" />
</div></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Dirección:</td>
<td> <div align="center">
<input type="text" name="Direccin" value="" size="40">
</div></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Teléfono:</td>
<td> <div align="center">
<input type="text" name="Telfono" value="" size="40">
</div></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Email:</td>
<td> <div align="center">
<input type="text" name="Email" value="" size="40">
</div></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Inicio de la obra:</td>
<td><div align="center">
<input type="text" name="Plazo_de_inicio" value="" size="40" />
</div></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Localidad de la obra:</td>
<td> <div align="center">
<input type="text" name="Localidad" value="" size="40">
</div></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Provincia de la obra:</td>
<td><div align="center">
<input type="text" name="Provincia" value="" size="40" />
</div></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Código postal:</td>
<td><div align="center">
<input type="text" name="Cdigo_postal" value="" size="40" />
</div></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Obra a realizar:<br />
(Ej: Reformar piso) </td>
<td><div align="center">
<input name="obra_realizar" type="text" id="obra_realizar" value="" size="40" />
</div></td>
</tr>
<tr valign="baseline">
<td align="right" valign="middle" nowrap>Descripci&oacute;n de la obra: </td>
<td><label>
<div align="center">
<textarea name="Descripcin" cols="34" rows="5" id="Descripcin"></textarea>
</div>
</label></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input name="submit" type="submit" value="Enviar" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</body>
</html>



Saludos cordiales.
  #4 (permalink)  
Antiguo 06/10/2008, 08:57
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Respuesta: Problemas con fecha en el formulario

Mensaje movido al foro de PHP desde Editores Web.

Saludos,
  #5 (permalink)  
Antiguo 07/10/2008, 04:49
 
Fecha de Ingreso: septiembre-2007
Mensajes: 50
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Problemas con fecha en el formulario

Estimado Javier.

No entiendo porqué has movido mi mensaje al foro de PHP cuando pongo muy claro que no tengo ni idea de PHP y mi página la estoy haciendo con Dreamweaver8 y todo el tema de la base de datos está hecho desde Dreamweaver (comportamientos de servidor, juego de registros, etc).

Ademas Juaniquillo veo que es una persona puesta en estos temas y pretendía ayudarme, tú por el contrario has hecho lo sencillo mover el mensaje sin preocuparte si se resuelven los problemas o no.

Por lo menos me podías indicar qué debo hacer en el foro PHP (Sin tener idea de PHP). ¿Les digo que hago la página con Dreamweaver?. Porque todo lo que me cuenten de PHP no lo voy a entender.

La verdad que haces un flaco favor a este foro con este comportamiento.

Saludos.
  #6 (permalink)  
Antiguo 07/10/2008, 04:55
Avatar de jaronu  
Fecha de Ingreso: febrero-2008
Mensajes: 2.183
Antigüedad: 16 años, 2 meses
Puntos: 52
Respuesta: Problemas con fecha en el formulario

Pues yo creo que JavierB, ha hecho lo que tenia que hacer, moverte el post al foro de php.

Y otra cosa si dejas que dreamweaver te haga el codigo php vas muy mal, por que no es un programa PERFECTO, y no te aconsejo que lo uses para programar en php y mysql.

lo que si te aconsejo es leer algun manual basico de PHP y en una hora sabras mas php que dreamweaver.

suerte
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:27.