0
<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

3
Contributors
10
Replies
11
Views
4 Years
Discussion Span
Last Post by lsabinano
0

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?

0

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.

0
 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.

0

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

0

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

what should i do sir??

0
<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.

0

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!

Edited by cereal

0
<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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.