ianhaney50 Posted November 4, 2015 Share Posted November 4, 2015 Thank you so much, works perfect I just found another little issue when testing, the record date is being inserted into the mysql table as 00/00/0000 instead of the actual date, I am using datepicker, the INSERT query is below if ($stmt = $mysqli->prepare("INSERT repairs (customer_name, customer_email, customer_phone, computer_make, computer_model, technician, status, exrdate, exrtime, exstdate, exstime, deltype, comments) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) The datepicker coding is below <script> $(function() { $( "#exrdate" ).datepicker({ showButtonPanel: true, dateFormat: "dd/mm/yy", showOn:"both" }); }); $(function() { $( "#exstdate" ).datepicker({ showButtonPanel: true, dateFormat: "dd/mm/yy", showOn:"both" }); }); </script> It was working before but not now for some reason the data type in the mysql table is date and has no NULL or default Quote Link to comment https://forums.phpfreaks.com/topic/299123-date-insert-issue/ Share on other sites More sharing options...
Barand Posted November 4, 2015 Share Posted November 4, 2015 (edited) You need to put dates into the database in yyyy-mm-dd format so if your datepicker is using dd/mm/yy then the date needs converting. You can do this in SQL with the method shown in this example INSERT INTO table (mydate) VALUES (STR_TO_DATE($datepickerdate, '%d/%m/%y') ) Edited November 4, 2015 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/299123-date-insert-issue/#findComment-1525468 Share on other sites More sharing options...
ianhaney50 Posted November 4, 2015 Author Share Posted November 4, 2015 Hi Barand I just added that to the INSERT query so now looks like the following if ($stmt = $mysqli->prepare("INSERT repairs (customer_name, customer_email, customer_phone, computer_make, computer_model, technician, status, exrdate, exrtime, (STR_TO_DATE($exstdate, '%d/%m/%y') ), exstime, deltype, comments) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) I selected 8/11/2015 within the datepicker but has outputted it as 10/4/2015 Quote Link to comment https://forums.phpfreaks.com/topic/299123-date-insert-issue/#findComment-1525471 Share on other sites More sharing options...
Barand Posted November 4, 2015 Share Posted November 4, 2015 Your implementation is nothing like my example. The STR_TO_DATE() in my example is in the VALUES(..) part, you have just added in the columns part. Quote Link to comment https://forums.phpfreaks.com/topic/299123-date-insert-issue/#findComment-1525473 Share on other sites More sharing options...
ianhaney50 Posted November 4, 2015 Author Share Posted November 4, 2015 So sorry, I thought the easier way would be to make the datepicker be in standard format of yy/mm/dd code and tested it and works perfect now and now displays on the page as 28/11/2015 so is perfect now, so sorry for being a pain Quote Link to comment https://forums.phpfreaks.com/topic/299123-date-insert-issue/#findComment-1525475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.