I have been trying to follow the example shown from this link below:
This is my code sample below:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
/** Variables */
$pdate = isset($_POST['pdate']) ? $_POST['pdate'] : '';
$org = mysqli_escape_string($dbcon, trim($_POST['org']));
$city = mysqli_escape_string($dbcon, trim($_POST['city']));
$state = isset($_POST['state']) ? $_POST['state'] : '';
$rio = mysqli_escape_string($dbcon, trim($_POST['rio']));
/** Query */
$q = "INSERT INTO `survey` (id, pdate, org, city, state, rio, date_created)
VALUES (NULL, STR_TO_DATE('$pdate', '%M %d, %Y'), '$org', '$city', '$state', '$rio', NOW())";
?>
/** Changing Datepicker Value **/
jQuery(document).ready(function($) {
/** Datepicker for the Form */
$('.selector').datepicker('option', 'dateFormat', 'yy-mm-dd');
});
$pdate = "2015-09-28"; Displays like that according to the <?php echo format ?>
There are two queries that you are using, should I use the STR_TO_TIME()
or FROM UNIXTIME()
When I try and follow the 3rd step:
$dt = DateTime::createFromFormat('m/d/Y', $_POST['pdate']);
$pdate = $dt->format('Y-m-d');
After submitting the form, I get undefined variable index.
What is it that I am now missing?