Jump to content

dates


anthony-needs-you

Recommended Posts

hi i have a date picker, here is my form field:

 

<input name="departureDate" type="text" class="fields" id="departureDateField" value="dd/mm/yy" onfocus="this.select();lcs(this)" onclick="event.cancelBubble=true;this.select();lcs(this)">

 

I pass this to:

 

<?php

 

if(isset($_POST['save']))

{

$departureDate  = $_POST['departureDate'];

$expireDate = $_POST['expireDate'];

$airport  = $_POST['airport'];

$resort = $_POST['resort'];

$hotel  = $_POST['hotel'];

$duration = $_POST['duration'];

$board  = $_POST['board'];

$price = $_POST['price'];

$specialoffer  = $_POST['specialoffer'];

$description = $_POST['description'];

$customerRef  = $_POST['customerRef'];

$mystiqueRef = $_POST['mystiqueRef'];

$stars  = $_POST['stars'];

 

 

 

if(!get_magic_quotes_gpc())

{

$departureDate  = addslashes($departureDate);

$expireDate = addslashes($expireDate);

$airport  = addslashes($airport);

        $resort  = addslashes($resort);

$hotel  = addslashes($hotel);

$duration = addslashes($duration);

$board  = addslashes($board);

        $price  = addslashes($price);

$specialoffer  = addslashes($specialoffer);

$description  = addslashes($description);

$customerRef = addslashes($customerRef);

$mystiqueRef  = addslashes($mystiqueRef);

        $stars  = addslashes($stars);

}

include 'library/config.php';

include 'library/opendb.php';                 

 

 

$query = "INSERT INTO test (departureDate, expireDate, airport, destination, resort, hotel, duration, board, price, specialoffer, description, customerRef, mystiqueRef, stars) VALUES ('$departureDate', '$expireDate', '$airport', '$destination', '$resort', '$hotel', '$duration', '$board', '$price', '$specialoffer', '$description', '$customerRef', '$mystiqueRef', '$stars')";

mysql_query($query) or die('Error, query failed : ' . mysql_error());

include 'library/closedb.php';

 

echo "<div class=\"alert\">Holiday '$mystiqueRef' added</div>";

}

?>

 

 

my sql is:

 

`departureDate` DATE NULL,

 

but all i get is:

 

0000-00-00

 

whatever date i put in

 

can someone please tell me what i've done  wrong, thanks

Link to comment
https://forums.phpfreaks.com/topic/137394-dates/
Share on other sites

Can you echo out the query to ensure they contain correct values:

 

$query = "INSERT INTO test (departureDate, expireDate, airport, destination, resort, hotel, duration, board, price, specialoffer, description, customerRef, mystiqueRef, stars) VALUES ('$departureDate', '$expireDate', '$airport', '$destination', '$resort', '$hotel', '$duration', '$board', '$price', '$specialoffer', '$description', '$customerRef', '$mystiqueRef', '$stars')";
echo $query;

Link to comment
https://forums.phpfreaks.com/topic/137394-dates/#findComment-717934
Share on other sites

i've echo the date and it shows as 17/12/2008

 

How do i change this to a mysql format would i change the value in the form?

 

<input name="departureDate" type="text" class="fields" id="departureDateField" value="yy/dd/mm" onfocus="this.select();lcs(this)" onclick="event.cancelBubble=true;this.select();lcs(this)">

Link to comment
https://forums.phpfreaks.com/topic/137394-dates/#findComment-717941
Share on other sites

Here's how I handle the date.

 

$newdate = date("Y-m-d", strtotime($_POST['departureDate']));

 

Then I add $newdate into the database:

"INSERT INTO test (departureDate, expireDate, ....) VALUES ('$newdate', '$expireDate', '$airport', '$destination', '$resort', '$hotel', '$duration', '$board', '$price', '$specialoffer', '$description', '$customerRef', '$mystiqueRef', '$stars')";
   

 

Link to comment
https://forums.phpfreaks.com/topic/137394-dates/#findComment-717987
Share on other sites

ok this is what i've got:

 

if(isset($_POST['save']))
{

$departureDate = date("Y-m-d", strtotime($_POST['departureDate']));
$expireDate = date("Y-m-d", strtotime($_POST['expireDate']));
$airport  = $_POST['airport'];
$resort = $_POST['resort'];
$hotel  = $_POST['hotel'];
$duration = $_POST['duration'];
$board  = $_POST['board'];
$price = $_POST['price'];
$specialoffer  = $_POST['specialoffer'];
$description = $_POST['description'];
$customerRef  = $_POST['customerRef'];
$mystiqueRef = $_POST['mystiqueRef'];
$stars  = $_POST['stars'];



if(!get_magic_quotes_gpc())
{
	$airport   = addslashes($airport);
        $resort  = addslashes($resort);
	$hotel   = addslashes($hotel);
	$duration = addslashes($duration);
	$board   = addslashes($board);
        $price  = addslashes($price);
	$specialoffer  = addslashes($specialoffer);
	$description   = addslashes($description);
	$customerRef = addslashes($customerRef);
	$mystiqueRef   = addslashes($mystiqueRef);
        $stars  = addslashes($stars);
}
include 'library/config.php';
include 'library/opendb.php';                   


$query = "INSERT INTO test (departureDate, expireDate, airport, destination, resort, hotel, duration, board, price, specialoffer, description, customerRef, mystiqueRef, stars) VALUES ('$departureDate', '$expireDate', '$airport', '$destination', '$resort', '$hotel', '$duration', '$board', '$price', '$specialoffer', '$description', '$customerRef', '$mystiqueRef', '$stars')";
echo $query;
mysql_query($query) or die('Error, query failed : ' . mysql_error()); 
include 'library/closedb.php';

echo "<div class=\"alert\">Holiday '$mystiqueRef' added</div>";
}   

 

--------------------------------------------------------------------------------------

 

and this is my form field:

 

<input name="departureDate" type="text" class="fields" id="departureDateField" value="dd/mm/yy" onfocus="this.select();lcs(this)" onclick="event.cancelBubble=true;this.select();lcs(this)">

 

For some reason it return the wrong date selected, has anyone have a clue whats wrong?

Link to comment
https://forums.phpfreaks.com/topic/137394-dates/#findComment-718257
Share on other sites

and also this, it got chopped from the above:

 

$query = "INSERT INTO test (departureDate, expireDate, airport, destination, resort, hotel, duration, board, price, specialoffer, description, customerRef, mystiqueRef, stars) VALUES ('$departureDate', '$expireDate', '$airport', '$destination', '$resort', '$hotel', '$duration', '$board', '$price', '$specialoffer', '$description', '$customerRef', '$mystiqueRef', '$stars')";

echo $query;

mysql_query($query) or die('Error, query failed : ' . mysql_error());

include 'library/closedb.php';

 

echo "<div class=\"alert\">Holiday '$mystiqueRef' added</div>";

}

Link to comment
https://forums.phpfreaks.com/topic/137394-dates/#findComment-718284
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.