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
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
Share on other sites

looks like you are asking users to enter the date in dd/mm/yy format, then you are trying to insert it into the DB in the same format.

 

in you database the date field is in yyyy-mm-dd  format.

 

maybe you should format the date to mysql format before trying to insert it

 

 

Link to comment
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.