Comunidad de diseño web y desarrollo en internet online

Problema enviando Fecha

Citar            
MensajeEscrito el 19 Ago 2008 07:07 pm
Tengo un formulario donde añado la fecha via un Calendario o via manual, lo importante es que si escribo la fecha como dd/mm/yyyy al momento de enviarlo via PHP a la base de datos en MySQL no eadmite el valor, pues me exige sea yyyymmdd , sin "/" y en ese orden, como puedo hacer para que PHP lo cambie antes de enviarlo, uso DreamWeaver y me genera este codigo automaticamente

Código :

<?php
session_start();

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"] == "user_form")) {
  $insertSQL = sprintf("INSERT INTO usuarios_ (pre_nombre, mas_nombre, ap_paterno, ap_materno, nacionalidad, f_nacimiento, doc_id, passport, sexo, status, tiene_hijos, foto, hijo_cant, direccion, telefono, correo, celular, niv_estudios, cent_estudios, vacuna1, vacuna2, vacuna3, vacuna4, vacuna5, vacuna6, of_base, date_ingreso, area, cargo_ingreso, nivel_actual, date_jc, date_jb, date_ja, date_cc, date_cb, date_ca, date_sb, date_sa, date_tsc, date_tsb, date_tsa, date_e, date_gc, date_gb, date_ga, date_dv, date_do, date_dr, date_dp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['pre_nombre'], "text"),
                       GetSQLValueString($_POST['mas_nombre'], "text"),
                       GetSQLValueString($_POST['ap_paterno'], "text"),
                       GetSQLValueString($_POST['ap_materno'], "text"),
                       GetSQLValueString($_POST['nacionalidad'], "text"),
                       GetSQLValueString($_POST['f_nacimiento'], "date"),
                       GetSQLValueString($_POST['doc_id'], "text"),
                       GetSQLValueString($_POST['passport'], "text"),
                       GetSQLValueString(isset($_POST['sexo']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['Status']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['tiene_hijos']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString($_POST['foto'], "text"),
                       GetSQLValueString($_POST['hijo_cant'], "int"),
                       GetSQLValueString($_POST['direccion'], "text"),
                       GetSQLValueString($_POST['telefono'], "text"),
                       GetSQLValueString($_POST['correo'], "text"),
                       GetSQLValueString($_POST['celular'], "text"),
                       GetSQLValueString($_POST['niv_estudios'], "text"),
                       GetSQLValueString($_POST['cent_estudio'], "text"),
                       GetSQLValueString(isset($_POST['vac1']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['vac2']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['vac3']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['vac4']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['vac5']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['vac6']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['of_base'], "text"),
                       GetSQLValueString($_POST['date_ing'], "date"),
                       GetSQLValueString($_POST['area'], "text"),
                       GetSQLValueString($_POST['cargo_ingreso'], "text"),
                       GetSQLValueString($_POST['nivel_actual'], "text"),
                       GetSQLValueString($_POST['date_jc'], "date"),
                       GetSQLValueString($_POST['date_jb'], "date"),
                       GetSQLValueString($_POST['date_ja'], "date"),
                       GetSQLValueString($_POST['date_cc'], "date"),
                       GetSQLValueString($_POST['date_cb'], "date"),
                       GetSQLValueString($_POST['date_ca'], "date"),
                       GetSQLValueString($_POST['date_sb'], "date"),
                       GetSQLValueString($_POST['date_sa'], "date"),
                       GetSQLValueString($_POST['date_tsc'], "date"),
                       GetSQLValueString($_POST['date_tsb'], "date"),
                       GetSQLValueString($_POST['date_tsa'], "date"),
                       GetSQLValueString($_POST['date_e'], "date"),
                       GetSQLValueString($_POST['date_gc'], "date"),
                       GetSQLValueString($_POST['date_gb'], "date"),
                       GetSQLValueString($_POST['date_ga'], "date"),
                       GetSQLValueString($_POST['date_dv'], "date"),
                       GetSQLValueString($_POST['date_do'], "date"),
                       GetSQLValueString($_POST['date_dr'], "date"),
                       GetSQLValueString($_POST['date_dp'], "date"));

  mysql_select_db($database_plexis, $plexis);
  $Result1 = mysql_query($insertSQL, $plexis) or die(mysql_error());
}


obviamente tengo el mismo problema con todos los date sin importar si ingreso al data manualmente o via el caledario,.

que linea debvo incluir y donde he probado en un archivo aparte reordenar la data y me sale con :

Código :

 <?php
$fecha = "29/06/1980";
$new_fecha = str_word_count($fecha,1,"0123456789");
print_r ($new_fecha);
$mod_fecha = $new_fecha[2].$new_fecha[1].$new_fecha[0];
echo "$mod_fecha";
?>


Lo que quiero saber es si debo incluir eso pero donde o com odebo de hacer, por favor me urge una solucion AUXILIO hermanos clabers.

Por NeoCesar

Claber

1415 de clabLevel

14 tutoriales

Genero:Masculino  

Algun lugar dentro de la Matrix (Lima - Perú)

firefox
Citar            
MensajeEscrito el 19 Ago 2008 07:52 pm
He logrado solucionar el problema, aqui el codigo corregido

Código :

<?php
session_start();

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']);
}

# Aqui estan las lineas de código añadidas
$new_fecha = str_word_count($_POST['f_nacimiento'],1,"0123456789");
$f_nacimiento = $new_fecha[2].$new_fecha[1].$new_fecha[0];
# Aqui termina la inclusion

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "user_form")) {
  $insertSQL = sprintf("INSERT INTO usuarios_ (pre_nombre, mas_nombre, ap_paterno, ap_materno, nacionalidad, f_nacimiento, doc_id, passport, sexo, status, tiene_hijos, foto, hijo_cant, direccion, telefono, correo, celular, niv_estudios, cent_estudios, vacuna1, vacuna2, vacuna3, vacuna4, vacuna5, vacuna6, of_base, date_ingreso, area, cargo_ingreso, nivel_actual, date_jc, date_jb, date_ja, date_cc, date_cb, date_ca, date_sb, date_sa, date_tsc, date_tsb, date_tsa, date_e, date_gc, date_gb, date_ga, date_dv, date_do, date_dr, date_dp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['pre_nombre'], "text"),
                       GetSQLValueString($_POST['mas_nombre'], "text"),
                       GetSQLValueString($_POST['ap_paterno'], "text"),
                       GetSQLValueString($_POST['ap_materno'], "text"),
                       GetSQLValueString($_POST['nacionalidad'], "text"),
                       #La siguietne variable ya no pasa como $_POST['f_nacimiento'] si no como $f_nacimiento establecida lineas arriba
                       GetSQLValueString($f_nacimiento, "date"),
                       GetSQLValueString($_POST['doc_id'], "text"),
                       GetSQLValueString($_POST['passport'], "text"),
                       GetSQLValueString(isset($_POST['sexo']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['Status']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['tiene_hijos']) ? "true" : "", "defined","'Y'","'N'"),
                       GetSQLValueString($_POST['foto'], "text"),
                       GetSQLValueString($_POST['hijo_cant'], "int"),
                       GetSQLValueString($_POST['direccion'], "text"),
                       GetSQLValueString($_POST['telefono'], "text"),
                       GetSQLValueString($_POST['correo'], "text"),
                       GetSQLValueString($_POST['celular'], "text"),
                       GetSQLValueString($_POST['niv_estudios'], "text"),
                       GetSQLValueString($_POST['cent_estudio'], "text"),
                       GetSQLValueString(isset($_POST['vac1']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['vac2']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['vac3']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['vac4']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['vac5']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['vac6']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['of_base'], "text"),
                       GetSQLValueString($_POST['date_ing'], "date"),
                       GetSQLValueString($_POST['area'], "text"),
                       GetSQLValueString($_POST['cargo_ingreso'], "text"),
                       GetSQLValueString($_POST['nivel_actual'], "text"),
                       GetSQLValueString($_POST['date_jc'], "date"),
                       GetSQLValueString($_POST['date_jb'], "date"),
                       GetSQLValueString($_POST['date_ja'], "date"),
                       GetSQLValueString($_POST['date_cc'], "date"),
                       GetSQLValueString($_POST['date_cb'], "date"),
                       GetSQLValueString($_POST['date_ca'], "date"),
                       GetSQLValueString($_POST['date_sb'], "date"),
                       GetSQLValueString($_POST['date_sa'], "date"),
                       GetSQLValueString($_POST['date_tsc'], "date"),
                       GetSQLValueString($_POST['date_tsb'], "date"),
                       GetSQLValueString($_POST['date_tsa'], "date"),
                       GetSQLValueString($_POST['date_e'], "date"),
                       GetSQLValueString($_POST['date_gc'], "date"),
                       GetSQLValueString($_POST['date_gb'], "date"),
                       GetSQLValueString($_POST['date_ga'], "date"),
                       GetSQLValueString($_POST['date_dv'], "date"),
                       GetSQLValueString($_POST['date_do'], "date"),
                       GetSQLValueString($_POST['date_dr'], "date"),
                       GetSQLValueString($_POST['date_dp'], "date"));

  mysql_select_db($database_plexis, $plexis);
  $Result1 = mysql_query($insertSQL, $plexis) or die(mysql_error());
}


Espero les sirva de ayuda a los que han tenido el mismo problema que yo ;)

Por NeoCesar

Claber

1415 de clabLevel

14 tutoriales

Genero:Masculino  

Algun lugar dentro de la Matrix (Lima - Perú)

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.