Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

j query datepicker not inserting date PHP mySQL

Engaged ,
Oct 15, 2013 Oct 15, 2013

i have used a jquery datepicker http://jqueryui.com/datepicker/

i have a databse with the following feild

Field | Type | Null | Default

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

date  | date  | No  | 0000-00-00

i have a page with the jqury date picker

  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />

  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>

  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

  <link rel="stylesheet" href="/resources/demos/style.css" />

  <script>

  $(function() {

    $( "#datepicker" ).datepicker();

  });

  </script>

and the following php and form feild

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

  $insertSQL = sprintf("INSERT INTO CalendarBetty (`date`) VALUES (%s)",

                       GetSQLValueString($_POST['date'], "date"));

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">

<input type="text" name="date" value="" id="datepicker" size="32" />

<input type="hidden" name="MM_insert" value="form1" />

when i add a date using the picker that is attached to the text feild it is storing the default value of 0000-00-00


TOPICS
Server side applications
9.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Oct 15, 2013 Oct 15, 2013

Here is the script I use to force the right formatting. You should be able to modify it for your use:

<script>

$.datepicker.setDefaults({

   showOn: 'focus',

   buttonText: '' });

   $("#date1").datepicker({dateFormat: 'yy-mm-dd'}); 

</script>

An alternative would be to use PHP to change the format before updating the database.

Translate
Engaged ,
Oct 15, 2013 Oct 15, 2013

looks like its the way the date is formatted. the jqury uses

00/00/0000

the database uses

0000-00-00

i need to get the jquery to change to the same as the DB


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Oct 15, 2013 Oct 15, 2013

Here is the script I use to force the right formatting. You should be able to modify it for your use:

<script>

$.datepicker.setDefaults({

   showOn: 'focus',

   buttonText: '' });

   $("#date1").datepicker({dateFormat: 'yy-mm-dd'}); 

</script>

An alternative would be to use PHP to change the format before updating the database.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 16, 2013 Oct 16, 2013

thanks, i tried

$.datepicker.setDefaults({

   showOn: 'focus',

   buttonText: '' });

   $("#date1").datepicker({dateFormat: 'yy-mm-dd'});

<input type="text" name="date" value="" id="date1" size="32" />

but that didnt display the date pciker

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 16, 2013 Oct 16, 2013

this done it

<script type="text/javascript">
       $
(function() {
               $
("#datepicker").datepicker({ dateFormat: "yy-mm-dd" }).val()
      
});
  
</script>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Oct 16, 2013 Oct 16, 2013
LATEST

That's right. You need to use your own variable ID. Sorry I didn't clarify that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines