Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/07/2012, 23:47
Zota
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Guardar fecha actual en campo

Hola a todos.

He realizado un formulario donde guardo unos registros y me anda bien. El problema es que necesito capturar la fecha actual y hora del sistema y que me aparezca en el campo de texto FechaEnvio automaticamente y que el usuario no pueda modificarlo para poder ser ingresado a la base de datos. me podrian ayudar con este paso? o hay otro metodo de enviar la fecha y hora actual por medio del formulario cuando se le haga clic? muchas gracias.

Dejo el codigo de lo que estoy haciendo. Gracias

Código PHP:
<?php require_once('../../../../Connections/conex.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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 guia (FechaEnvio, Remitente, Destinatario, Prioridad, Destinos, TipoEnvio, Transporte, NomRemitente, MovilRemitente, EmailRemitente, NomDestino, MovilDestino, EmailDestino, FechaLlegada, ConfirmaRecepcion, EstadoEnvio, Observacion, Numero) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['FechaEnvio'], "date"),
                       
GetSQLValueString($_POST['Remitente'], "text"),
                       
GetSQLValueString($_POST['Destinatario'], "text"),
                       
GetSQLValueString($_POST['Prioridad'], "text"),
                       
GetSQLValueString($_POST['Destinos'], "text"),
                       
GetSQLValueString($_POST['TipoEnvio'], "text"),
                       
GetSQLValueString($_POST['Transporte'], "text"),
                       
GetSQLValueString($_POST['NomRemitente'], "text"),
                       
GetSQLValueString($_POST['MovilRemitente'], "text"),
                       
GetSQLValueString($_POST['EmailRemitente'], "text"),
                       
GetSQLValueString($_POST['NomDestino'], "text"),
                       
GetSQLValueString($_POST['MovilDestino'], "text"),
                       
GetSQLValueString($_POST['EmailDestino'], "text"),
                       
GetSQLValueString($_POST['FechaLlegada'], "date"),
                       
GetSQLValueString($_POST['ConfirmaRecepcion'], "text"),
                       
GetSQLValueString($_POST['EstadoEnvio'], "text"),
                       
GetSQLValueString($_POST['Observacion'], "text"),
                       
GetSQLValueString($_POST['Numero'], "text"));

  
mysql_select_db($database_conex$conex);
  
$Result1 mysql_query($insertSQL$conex) or die(mysql_error());
}
?>
<!DOCTYPE html >

<html>

<head>
    <title></title>
    <meta  charset="iso-8859-1" />
    <link href="../css/style.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
        <link href="css/ie6.css" rel="stylesheet" type="text/css" />
    <![endif]-->
    <!--[if IE 7]>
        <link href="css/ie7.css" rel="stylesheet" type="text/css" />  
    <![endif]-->
    <link href="../../../css/ie6.css" rel="stylesheet" type="text/css">
    <link href="../../../css/ie7.css" rel="stylesheet" type="text/css">
    <link href="../../../css/style.css" rel="stylesheet" type="text/css">
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <style type="text/css">
<!--
.Estilo1 {
    font-size: 20px;
    font-weight: bold;
}
-->
    </style>
</head>

<body>


      <div id="background">
              <div id="page">
              
                     <div class="header">
                        <div class="footer">
                            <div class="body">
                              <div id="sidebar"><a href="../index.html"><img id="logo" src="../../../../images/logo.gif" with="154" height="74" alt="" title=""/></a>
<ul class="navigation">
                                                <li><a  href="../PanelAdministrador.php">Panel Admistrador</a><a  href="../PanelAdministrador.php"></a></li>
                                              <li ></li>
                                </ul>
                                        
                              </div>
<div id="content">
                                                <div class="content">
                                               <ul class="article">
                                                    <li>
                                                      <h2 align="right">Bienvenido: </h2>
                                                 </li>
                                                    
                                                    <li><?

$Fecha
date('Y-m-d');
$Horadate('H:i:s');


echo 
"Fecha: ".$Fecha;
echo 
"<br>";
echo 
"Hora: ".$Hora;


?> </li>
                                                    <li>
                                                      <form method="post" name="form1" action="<?php echo $editFormAction?>">
                                                        <table align="center">
                                                          <tr valign="baseline">
                                                            <td nowrap align="right">FechaEnvio:</td>
                                                            <td><input name="FechaEnvio" type="text" size="32"></td>
                                                          </tr>
                                                          <tr valign="baseline">
                                                            <td nowrap align="right">Remitente:</td>
                                                            <td><input type="text" name="Remitente" value="" size="32"></td>
                                                          </tr>
                                                          <tr valign="baseline">
                                                            <td nowrap align="right">Destinatario:</td>
                                                            <td><input type="text" name="Destinatario" value="" size="32"></td>
                                                          </tr>
                                                          <tr valign="baseline">
                                                            <td nowrap align="right">Prioridad:</td>
                                                            <td><input type="text" name="Prioridad" value="" size="32"></td>
                                                          </tr>
                                                          <tr valign="baseline">
                                                            <td nowrap align="right">Destinos:</td>
                                                            <td><input type="text" name="Destinos" value="" size="32"></td>
                                                          </tr>
                                                          <tr valign="baseline">
                                                            <td nowrap align="right">TipoEnvio:</td>
                                                            <td><input type="text" name="TipoEnvio" value="" size="32"></td>
                                                          </tr>
                                                          <tr valign="baseline">
                                                            <td nowrap align="right">Transporte:</td>
                                                            <td><input type="text" name="Transporte" value="" size="32"></td>
                                                          </tr>
                                                          <tr valign="baseline">
                                                            <td nowrap align="right">NomRemitente:</td>
                                                            <td><input type="text" name="NomRemitente" value="" size="32"></td>
                                                          </tr>
                                                          <tr valign="baseline">
                                                            <td nowrap align="right">&nbsp;</td>
                                                            <td><input type="submit" value="Insertar registro"></td>
                                                          </tr>
                                                        </table>
                                                        <input type="hidden" name="MM_insert" value="form1">
                                                      </form>
                                                      <p>&nbsp;</p>
                                                    </li>
                                                 <li><strong>Cerrar sesi&oacute;n </strong><strong><img src="../../../../images/Icons/Panel/Clave.png" alt="Cerrar Sesion" width="48" height="48"></strong></li>
                                                 <p>&nbsp;</p>
                                               </ul>
            </div>
                              </div>
                            </div>
                        </div>
                </div>
                     <div class="shadow">
                     </div>
              </div>    
      </div>    
    
</body>
</html>