How to pass value from datepicker to database? - php

by using form and post method in my program. It seems like my values of calendar are not able to insert into my database. I'm using jquery's datepicker and php to code. Please advice. Thanks

chances are your database is structured with a date format or datetime format. This is fine, but you will have to change the format of the date in the jquery UI after it is posted. Therefore if you have it as 12/19/2010 it would have to be changed to 2010-12-19 for the database to accept it. This is just a random guess since I don't know much more from your question.

Related

AngularJs DatePicker and Ajax - which format to store in MySql database?

I want to create a new object, with a start & end date using the standard UI-bootstrap DatePicker.
I will send these date, using Ajax, to my server, where some PHP which I code will store it in a MySql database.
Coming from a PHP background, my first instinct is to store date/time as a Unix timestamp.
Since (Angular) JS has a millisecond resolution and Unix timestamps have a second resolution, that involves multiplying/dividing by 1000.
My server is returning data as a JSON, and I would rather not change that.
Ideally, I would like to do any conversion on the server, since it ought to have more processing power, and just initialze by AngularJS model fronm the JSON received.
Would it be acceptable to store the date as strings in the MySql database, rather than a timestamp? That way the downloaded data could be used unchanged to initialize the DatePicker.
Since I am having trouble getting the DatePicker to show the date which it receives from the server (as Unix timestamp), this seems like the simpler approach, but is there anything to watch out for, if I do so?
How do others do this?

Time Format for Filemaker PHP

I'm having an issue with the FileMaker PHP API. I don't know how to format a time correctly for input into a Time field.
I tried entering a string with the format that the documentation guide says (H:M where H can be 24 hours) and it still doesn't take. I don't know if I'm supposed to change the data type with another function like date() or what.
Edit: A little snippet of code
//Date
if($arrDate!=NULL){
$booking->setField('arrival_date', '07/17/2015');
}
//Time
if($arrTime!=NULL){
$booking->setField('arrival_time', '11:00:00');
}
$savedBooking = $booking->commit();
I replaced the variables for the value fields with what they should be just in case it was something going wrong with them, but it still doesn't work. The date field setting works fine if I comment out the Time section however.
Here's the format that I use:
$booking->setField('arrival_date', date ( "n/j/Y H:i:s A" ) );
If you're interested in adjusting the time, here's a post to checkout: http://timdietrich.me/blog/php-timezone-arithmetic/
Good luck!
I suspect you may have some validation set up on the "arrival_time" time field. What is the error that is returned by the API? It should return an error code that will tell you more.
Also worth mentioning that FileMaker will inherit the date and time settings from your system settings. For example, date formats are different in Europe than they are in the states. But that time value you give looks like it would work, and you only get an error when setting that field, so I would look to make sure the field is defined correctly.
You can also test by putting that value in via FM Pro and see what happens.
I'm an idiot, after hours struggling with this I realized I had put the wrong field name! Thanks for your help guys. A string of H:M worked perfectly.

Make this form send a php database query by setting Jquery Variables?

I'm trying to convert jquery actions into variables that would eventually be sent off to a php query to search the database.
I'm thinking that some things such as text inputs can be stored as strings, while I'm unsure how I should treat checkboxes.
For example:
I have a checkbox such as 'please include all that interests you":
Beer
Wine
Sweets
Should I make each label a seperate TRUE/FALSE boolean in the database?
See my complete jsfiddle form and try to advise me (mind though,I'm a begginer in php,mysql and jquery :) )
Thank you everyone!
http://jsfiddle.net/pufamuf/TYT92/
You can use json for store all option.
For example you can store your form in a json string and pass it with jquery ($.ajax)
{"hobbies": {"football": true,"cricket": false,"basket":true}}
try with http://braincast.nl/samples/jsoneditor/
and using json_encode and json_decode in php.
You can store those checkboxes variables as tiny int or Boolean in the database Or you can store them in a single column (text) data type as json format like this [{"beer":0,"wine":1}] .and that's in case of increasing those options in the future and also you can use json_ encode json_decode to convert array to json format in PHP

free calendar with timestamp

I am working on form and I am looking for a free calendar/date/timestamp app that i can include in my form. basically, in the input text, i want users to click on the calendar icon and pick a date and a time stamp. that value should populate in the input text.
my next question is, in my mysql db, i am calling this field as "datetime", so i am hoping the values can be written in the db.
i am working with php and mysql.
thanks.
For the user interface you are describing to be added to the input field, jQuery Datepicker springs to mind.
http://jqueryui.com/demos/datepicker/
You'll need to include the jQuery library as well as the jQuery UI library. You can use the 'build your download' link and documentation on the jQuery library page to get a fully themed ui download to suit your design needs.
You'll need to make your form post to a server-side script that will take the field and insert it into the DB. Be careful - mysql date time is in the following format - YYYY-MM-DD HH:mm:SS. You can use strtotime and date to format the input from jQuery. After sanitizing the input, you could do something simple like:
date('Y/m/d H:i:s', strtotime($_POST['date']) )
You can use this to make sure in your server script that the date/time is in the proper format before it goes in the database.
This can be done with GUI
Take a look at jQuery UI Date-picker: http://jqueryui.com/demos/datepicker/
Regards to the date conversion there is plenty of functions to help you
http://www.php.net/manual/en/ref.datetime.php

Make timezone dropdown list populate with available timezones on a per Country basis?

I just noticed something really nice on the Google Analytics signup page for adding a new domain. First you pick a country them you pick your timezone. Instead of showing a huge Timezone list though they populate the timezone list with only timezones that are available for the country you have selected. I think this is a great idea to make picking a timezone easiar for some users.
So I would like to do this with jQuery since most my other javascript is using jquery already. Has anyone seen any existing jquery script that can do this for me? Or possibly how I can figure out what timezones are in each country?
Can't help with jQuery but for how to figure out what timezones are in each country, you can use DateTimeZone::listIdentifiers() with DateTimeZone::PER_COUNTRY as first argument and the ISO 3166-1 compatible country code as second argument, e.g.
DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, 'GB');
Note: PHP 5.3 is required.
You can construct the data you want from this table: http://www.datelib.de/Timezones.shtml.en. You would simply group by the Country code column. Probably the best way to go would be to throw all this data into a database table and use some AJAX magic to handle select menu onchange events.

Categories