www.webdeveloper.com
Results 1 to 10 of 10

Thread: Submitting dates to a Database ??

  1. #1
    Join Date
    May 2004
    Posts
    288

    Submitting dates to a Database ??

    im trying to submit a dates to my database by using a jquery UI datepicker
    but it seems to be entering the date into the database as 0000-00-00

    The thing that im trying to achieve is a site where people can guess the date of an event happening and they use the datepicker to pick the date.

    Ill also have a page that will display all the predictions but i want to display the dates like this example

    Monday 11th August 2011


    I also want to be able to display all the predictions for each month on their own pages

    Is there something i have to do so change the way the date is sent to the DB so i can have it in the format that i want or do i have create separate columns for day month year??

  2. #2
    Join Date
    Mar 2009
    Location
    Yorkshire
    Posts
    266
    I dont know what format jquery sends the date over as but entering the date into the db as YYYY-mm-dd wont cause you too many problems as there are functions in MYSQL itself that will let you format dates as you retrieve them.

    Another option would be to store the information as a timestamp in the db. Simply work out what format jquery is sending the data as, break the data up and use it in mktime(). Then when you retrieve it from the db you can use the date() function to format it however you want.

  3. #3
    Join Date
    May 2004
    Posts
    288
    im kinda new to php is there anyway you could show me an example of this?

  4. #4
    Join Date
    Mar 2009
    Location
    Yorkshire
    Posts
    266
    This example assumes the date is in dd/mm/YY.

    PHP Code:
    $date="28/07/2011";
    //check date format here before continuing.
    list($day,$month,$year)=explode('/',$date);
    $timestamp=mktime(0,0,0,$month,$day,$year);
    //insert into db.
    //retrieve from db at your leisure and simply
    $data=$timestamp//would be your timestamp from db, have taken from above for simplicity
    echo date('l jS F Y',$data); 

  5. #5
    Join Date
    May 2004
    Posts
    288
    totally lost me...

    how do i add this to work with the jquery datepicker?

  6. #6
    Join Date
    May 2004
    Posts
    288
    the form with the datepicker is currently submitting 000-00-00 into the date column

  7. #7
    Join Date
    Mar 2009
    Location
    Yorkshire
    Posts
    266
    Right, sorry about all the edits....

    Basically, the data from jquery IS submitting to the database, however it is inserting 0000-00-00. This is because the date you are trying to insert is in the wrong format (i think).

    Plan of action:

    Go to the script that inserts the data into the database.

    Put this line of php at the top:
    PHP Code:
    print_r($_POST); //or $_GET (depending on how the info is submitted) 
    This should output the information sent to that script. Find the date and post the format back on here. Ill rewrite the code i gave you above to match that format and then tell you where to put it
    Last edited by ryanlund; 07-29-2011 at 06:48 AM.
    Ryan Lund

    Development Manager
    http://www.ifindpoker.com

  8. #8
    Join Date
    May 2004
    Posts
    288
    I dont have access to my hosting just now but ill will later on and get back to you, thanks

  9. #9
    Join Date
    May 2004
    Posts
    288
    ok ive added that line of code and im gettin this return when i sbmut the form

    Array ( [firstname] => tom [lastname] => anderson [email] => tom@gmail.com [date] => 08/10/2011 ) Database updated with:tomandersontom@gmail.com

    when i check the DB the date field is still showing an entry as 0000-00-00

  10. #10
    Join Date
    Mar 2009
    Location
    Yorkshire
    Posts
    266
    Sorry for the slow reply, had a bit of a mad weekend xD Anyway, what you need to do...in an appropriate place in the script you put the previous code in...

    PHP Code:
    $date=$_POST['date']; //or $_GET 
    //check date format here before continuing.
    list($day,$month,$year)=explode('/',$date);
    $timestamp=mktime(0,0,0,$month,$day,$year);
    $final_date=date('Y-m-d',$timestamp); 
    then you can put $final_date into the db and it should work
    Last edited by ryanlund; 08-02-2011 at 08:47 AM.
    Ryan Lund

    Development Manager
    http://www.ifindpoker.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles