View Full Version : Help with the Jason's Calendar passing date to Mysql Database

02-19-2009, 03:25 PM
1) Script Title:
Jason's input Date Calendar

2) Script URL (on DD):

3) Describe problem:
I have tried to pass the date into mysql database but:confused: AND yes I have already looked at all the previous posts but nothing is working.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" src="calendarDateInput.js">

* Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm
* Script featured on and available at http://www.dynamicdrive.com
* Keep this notice intact for use.

$DBConnect = @mysql_connect("localhost", "root");
if (!$DBConnect)
{die("<p>The database server is not available</p>");

$dbselect = @mysql_select_db("hairsalon");

if (!$dbselect){
die("<p>The database is not available</p>");

$inp = $_POST['date']; // Get the textbox that holds the date
$table_name='bookings'; // Set the name of your table
$col_name = 'booking_date'; // Set the column that will hold the dates

$sQuery = "INSERT INTO $table_name($col_name) VALUES ('mysql_real_escape_string($inp)')"; // Insert query
mysql_query($sQuery) or die(mysql_error()); // Do the query


<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<script>DateInput('date', true, 'YYYY-MM-DD')</script>
<input type="submit" name="submit" value="Submit">


when i try to submit the date into the database it enters 0000-00-00, I think there is something wrong with my date format but dont know what.

I have changed the "defaultdateformat" into calendar.js file aswel,Dont know what other changed I am suppose to make.

Any help would be really appreciated.

02-19-2009, 05:26 PM
Hey, I have found a nice little code which solved my problem, Hope its helpful to people out there who are having similar problems

Fist of all dont make any changes to your date format leave it as it is.

Then after your insert query add

//This function encodes will change any type of date and format it to (YYYY-mm-dd) and will store the date into mysql table
function encodeDate ($inp) {
$tab = explode ("-", $inp);
$r = $tab[2]."-".$tab[1]."-".$tab[0];
return $r;

My script works now :D YAY ME!!!