Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/03/2007, 22:41
mogego
 
Fecha de Ingreso: marzo-2007
Mensajes: 6
Antigüedad: 17 años, 1 mes
Puntos: 0
Cambiar fechas dd-mm-yyyy(PHP) a yyyy-mm-dd(MySql)

Espero me ayuden a solucionar ete problema de fechas para guardarlas en una bases de datos MySql, al colocar la funcion que debe realizar el cambio de fecha para almacenarlo enla base de datos no me devuelve ningún error pero enla base de datos se graba 0000-00-00 y no la fecha ingresada, no se en donde esta el error?

este es el php subrayado en rojo el scritp para el cambio de fecha:

<?php
//set the database connection variables
$dbHost = "localhost";
$dbUser = "root";
$dbPass = "";
$dbDatabase = "moisesgo_euro";
//connet to the database
$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");

// Define post fields into simple variables

$first_name = $_POST['first_name'];

$last_name = $_POST['last_name'];

$email = $_POST['email'];

$phone = $_POST['phone'];

$date_pick = $_POST['date_pick'];

$hour_pick = $_POST['hour_pick'];

$place_pick = $_POST['place_pick'];

$airline = $_POST['airline'];

$flight = $_POST['flight'];

$date_drop = $_POST['date_drop'];

$hour_drop = $_POST['hour_drop'];

$place_drop = $_POST['place_drop'];

$id_easy = $_POST['id_easy'];

$vehicle = $_POST['vehicle'];

/* Let's strip some slashes in case the user entered

any escaped characters. */

$first_name = stripslashes($first_name);

$last_name = stripslashes($last_name);

$email = stripslashes($email);

$phone = stripslashes($phone);

$date_pick = stripslashes($date_pick);

$hour_pick = stripslashes($hour_pick);

$place_pick = stripslashes($place_pick);

$airline = stripslashes($airline);

$flight = stripslashes($flight);

$date_drop = stripslashes($date_drop);

$hour_drop = stripslashes($hour_drop);

$place_drop = stripslashes($place_drop);

$id_easy = stripslashes($id_easy);

$vehicle = stripslashes($vehicle);


/* Do some error checking on the form posted fields */

if((!$first_name) || (!$last_name) || (!$email) || (!$phone) || (!$date_pick) || (!$hour_pick) || (!$place_pick) || (!$date_drop) || (!$hour_drop) || (!$place_drop) || (!$vehicle)){

echo '<center><basefont size="2" face="Arial, Helvetica, sans-serif" color="#000000">You did not submit the following required information!</center>';

if(!$first_name){

echo "<center>First Name is a required field. Please enter it below.</center>";

}

if(!$last_name){

echo "<center>Last Name is a required field. Please enter it below.</center>";

}

if(!$email){

echo "<center>Email Address is a required field. Please enter it below.</center>";

}

if(!$phone){

echo "<center>Phone Number is a required field. Please enter it below.</center>";

}

if(!$date_pick){

echo "<center>Date Pick is a required field. Please enter it below.</center>";

}

if(!$hour_pick){

echo "<center>Hour Pick is a required field. Please enter it below.</center>";

}

if(!$place_pick){

echo "<center>Place Pick is a required field. Please enter it below.</center>";

}

if(!$date_drop){

echo "<center>Date_drop is a required field. Please enter it below.</center>";

}

if(!$hour_drop){

echo "<center>Hour Drop is a required field. Please enter it below.</center>";

}

if(!$place_drop){

echo "<center>Place Drop is a required field. Please enter it below.</center>";

}


if(!$vehicle){

echo "<center>Select a Vehicle Type is a required field. Please enter it below.</center>";

}

include 'ilus_cen.htm'; // Show the form again!

/* End the error checking and if everything is ok, we'll move on to

creating the user account */

exit(); // if the error checking has failed, we'll exit the script!

}

// Enter info into the Database.

$info2 = htmlspecialchars($info);

function fecha_mysql($date_pick)
{
ereg( "([0-9]{1,2})/([0-9]{1,2})/([0-9]{2,4})", $date_pick, $mifecha);
$fecha_lista=$mifecha[3]."-".$mifecha[2]."-".$mifecha[1];
return $fecha_lista;
}



$sql = mysql_query("INSERT INTO reservations (first_name, last_name,

email, phone, date_pick, hour_pick, place_pick, airline, flight,

date_drop, hour_drop, place_drop, id_easy, vehicle)

VALUES('$first_name', '$last_name', '$email',

'$phone', '".fecha_mysql($date_pick)."', '$hour_pick', '$place_pick', '$airline', '$flight',

'$date_drop', '$hour_drop', '$place_drop', '$id_easy', '$vehicle')")

or die (mysql_error());

if(!$sql){

echo '<center><basefont size="2" face="Arial, Helvetica, sans-serif" color="#000000">There has been an error creating your account. Please contact the webmaster.</center>';

} else {

$reser_id = mysql_insert_id();

// Let's mail the user!

$subject = "Euro American Reservation - $last_name";

$message = "<html>
<head>
<title>Euro American Reservation</title>
</head>
<body>
Thank you for choosing Euro American Rent-A-Car,
<br>
<br>
Confirmation: $reser_id Status: Confirmed <br>
<br>
<strong>Renter Information</strong><br>
<strong>Name:</strong> $first_name<br>
<strong>Last Name:</strong> $last_name<br>
<strong>Email:</strong> $email<br>
<strong>Phone:</strong> $phone
</p>

<p><strong>Pick Up Information</strong><br>
<strong>Date Pick Up:</strong> $date_pick<br>
<strong>Hour Pick Up:</strong> $hour_pick<br>
<strong>Place Pick up:</strong> $place_pick<br>
<strong>Airline:</strong> $airline<br>
<strong>Flight:</strong> $flight</p>

<p><strong>Drop Off Information</strong><br>
<strong>Date Drop Off:</strong> $date_drop<br>
<strong>Hour Drop Off:</strong> $hour_drop<br>
<strong>Place Drop Off: </strong>$place_drop</p>

<p><strong>Id Client: </strong>$id_easy</p>
<p><strong>Vehicle: </strong>$vehicle</p>

<p>Customer Service<br>
Euro American<br>
Rent-A-Car - Tours <br>
This is an automated response, please do not reply!&quot;</p>
</body>
</html>";

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: EuroAmerican Reservations <[email protected]>' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

mail($email, $subject, $message, $headers);

echo 'Your confirmation has been mailed to your email address!

exit;
}
?>