<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Date Picker</title>
    <link href="jquery-ui-1.8.24.custom/css/start/jquery-ui-1.8.24.custom.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="jquery-ui-1.8.24.custom/js/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="jquery-ui-1.8.24.custom/js/jquery-ui-1.8.24.custom.min.js"></script>
    <script type="text/javascript">
    $("document").ready(function(){
        $("#datepickerID").datepicker({
            changeYear: true
            })
            dateFormat:"%Y-%m-%d"
    });
    </script>
</head>
<body>
<form method="post" action="datePicker.php">
<label>
<input type="text" name="datepickerID" id="datepickerID" value="<?php echo $datepickerID; ?>"><img src="../images/calendar-icon-vector-801455.jpg" width="21" height="21">
</label><br/><br/>
<input type="submit" name="Submit"/>
</form>
<?php 
include('connect_to_db.php');

 if($_SERVER['REQUEST_METHOD'] == 'POST')
 { 
 // get form data, making sure it is valid
 $datepickerID = mysql_real_escape_string($_POST['datepickerID']);
 }
 if ($datepickerID == '')
 {
  mysql_query("INSERT date SET date_acquired='$date_acquired'")
 or die(mysql_error()); }
?>
</body>
</html>

am having problems inserting the datepicker in database....am a beginner in php you see....i need your help please...T_T

what are the problems you are having?
is it
1, the date does not write at all to the database.

or

2, it writes junk to the database?

it does not write at all in the database...

you seem to be trying to set the date value for the field 'date_acquired'

if so then you have to set the value as

date_acquired=$_POST['datepickerID'];

also on line 21

get rid of

value="<?php etc...">

just use

value=""

as jquery will set that value.

 if($_SERVER['REQUEST_METHOD'] == 'POST')
 { 
 // get form data, making sure it is valid
 $datepickerID = mysql_real_escape_string($_POST['datepickerID']);
 }

This part of the code will return

$datepickerID = "10/10/10" etc or it will return false.

Therefore your next line of code will not work unless the variable is blank.

it stored already sir but it's showing this result "0000-00-00".....T_T

sorry for the late reply...and thank you for helping me...^_^

it won't change...the result in the database is still "0000-00-00"...T_T

what should i do sir??

<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Date Picker</title>
<link rel="stylesheet" type="text/css" href="../jqueryUI/css/ui-lightness/jquery-ui-1.8.20.custom.css" />
<script type="text/javascript" src="../jquery/jquery.1.4.2.js"></script>
<script type="text/javascript" src="../jqueryUI/js/jquery-ui-1.8.20.custom.min.js"></script>
    <script type="text/javascript">
    $("document").ready(function(){
        $("#datepickerID").datepicker({
            changeYear: true
            })

    });
    </script>
</head>
<body>
<form method="post" action="datePicker.php">
<label>
<input type="text" name="datepickerID" id="datepickerID" value="">
</label><br/><br/>
<input type="submit" name="Submit"/>
</form>
<?php 
//include('connect_to_db.php');
 if($_SERVER['REQUEST_METHOD'] == 'POST')
 { 
 // get form data, making sure it is valid
    $datepickerID = mysql_real_escape_string($_POST['datepickerID']);
    echo "datepicker ".$datepickerID;
    list($month,$day,$year) = explode("/",$datepickerID);
    echo " month ".$month;
    echo " day ".$day;
    echo " year ".$year;
 }
// if ($datepickerID == '')
// {
//  mysql_query("INSERT date SET date_acquired='$datepickerID'")
// or die(mysql_error()); }
?>
</body>
</html>

The code above will show you what is output into the variable $datepickerID.
After that I have shown you how you can explode this variable to access each part of the date. You can then repack this into any format you want and write it to the database.

OR

I would change the field type to INT from DATE.
I would then use this code.

mysql_query("INSERT INTO tablename (date_aquired) VALUES (gregoriantojd($month,$day,$year))");

this will write an INT value into the database and it is alot easier to search and manipulate an INT value rather than a date value.

If the date_aquired field is already datetime you can also use strtotime():

$date = mysql_real_escape_string($_POST['datepickerID']);
$datepickerID = date('Y-m-d H:i:s', strtotime($date));

bye!

<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Date Picker</title>
<link rel="stylesheet" type="text/css" href="jquery-ui-1.8.24.custom/css/start/jquery-ui-1.8.24.custom.css" />
<script type="text/javascript" src="jquery-ui-1.8.24.custom/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.24.custom/js/jquery-ui-1.8.24.custom.min.js"></script>
    <script type="text/javascript">
    $("document").ready(function(){
        $("#datepickerID").datepicker({
            changeYear: true
            })
    });
    </script>
</head>
<body>
<form method="post" action="date_view.php".php">
<label>
<input type="text" name="datepickerID" id="datepickerID" value=""/>
</label><br/><br/>
<input type="submit" name="Submit"/>
</form>
<?php 
//include('connect_to_db.php');
include('connect_to_db.php');

 if($_SERVER['REQUEST_METHOD'] == 'POST')
 { 
 // get form data, making sure it is valid
    $datepickerID =mysql_real_escape_string($_POST['datepickerID']);
    echo "datepicker ".$datepickerID;
    list($month,$day,$year) = explode("",$datepickerID);
    echo " month ".$month;
    echo " day ".$day;
    echo " year ".$year;
 }
if ($datepickerID == '')
{
mysql_query("INSERT date SET date_acquired='$date_acquired'")
or die(mysql_error()); }
?>
</body>
</html>

good afternoon sir..^_^
i have this code...but it still show '0000-00-00' date...
sorry...am really just not good at this....i've tried doing all those things that you suggested...but the result is still the same....T_T

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.