尝试使用jquery datetimepicker,我可以让插件工作,但是,当我发布数据时,它不会在数据库中更新。其他所有内容都会更新,但日期/时间会更新。
注意:我意识到其中一些仍然是mysql,我正在努力更新整个网站。
edit_release_form.php,我有
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script type="text/javascript" src="http://vmcnucmed.cvm.umn.edu/includes/js/jquery-ui-timepicker-addon.js"></script>
<link rel="stylesheet" href="http://vmcnucmed.cvm.umn.edu/includes/jquery-ui-timepicker-addon.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<script>
$( function() {
$('#datetime_released').datetimepicker({
controlType: 'select',
oneLine: true,
timeFormat: 'hh:mm:ss tt'
});
} );
</script>
我的意见:
<input tabindex="1" id="datetime_released" type="text" name="datetime_released" >
post.php中
<?php
// Database Conection Parameters
define('DB_SERVER', "hostname");
define('DB_USER', "username");
define('DB_PASSWORD', "password");
define('DB_TABLE', "database");
// Connection to the Database
$mysqli = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_TABLE);
$mysqli->set_charset("utf8");
$mysqli->query("SET NAMES 'utf8'");
if (mysqli_connect_errno($mysqli)) {
trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR);
}
$datetime_released = $_POST['datetime_released'];
$release_probeSN = $_POST['release_probeSN'];
$release_reading = $_POST['release_reading'];
$release_reading_loc = $_POST['release_reading_loc'];
$releasedby = $_POST['releasedby'];
$id = $_POST['id'];
// Query
$sql = "
UPDATE xxx
SET datetime_released=?,
release_probeSN=?,
release_reading=?,
release_reading_loc=?,
releasedby=?
WHERE patientdoseID=?";
if(!($stmt = $mysqli->prepare($sql)))
{
die("Unable to prepare statement");
}
else
{
$stmt->bind_param("sissii", $datetime_released, $release_probeSN, $release_reading, $release_reading_loc, $releasedby, $id);
if($stmt->execute())
{
echo 'Patient Updated Successfully. <br /><br />Database ID: <br>';
header('Location: http://vmcnucmed.cvm.umn.edu',
TRUE, // rewrite existing Location header
302 // set status code
);
}
else
{
die("Update failed");
}
}
mysqli_close($mysqli);
?>
答案 0 :(得分:1)
这是你如何将发布的js日期转换为mysql格式。 PHP DateTime对象可以接受各种格式,通常可以正确转换它们。 为了便于阅读,您可以轻松地将其打包成一个函数。
<?php
// set your timezone somewhere prior to creating a DateTime object
// to prevent local vs UTC issues
date_default_timezone_set('America/Chicago');
// mysql date format
$format = "Y-m-d H:i:s";
// an example input
$input = '08/25/2016 05:19:20 am';
// convert input date into a PHP DateTime object
$my_date = new DateTime($input);
// create a string in the desired mysql format
$output = $my_date->format($format);
echo $output;
// outputs 2016-08-25 05:19:20 - just the way mysql likes it