【发布时间】:2017-05-20 21:07:27
【问题描述】:
我正在尝试向我的数据库添加一个日期 我的表单上有一个 jQuery 数据选择器,但它添加了一个类似 M - d - y 的日期,我的数据库不接受它。在添加到数据库之前,我需要添加一些内容来更改日期。
date('Y-m-d H:i:s', strtotime($date));
我不知道我需要在哪里添加任何想法
<?php include('connect2.php'); ?>
<!doctype html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="jqueryui/jquery-ui.css">
<link type="text/css" rel="stylesheet" href="jqueryui/jquery-ui.structure.css">
<link type="text/css" rel="stylesheet" href="jqueryui/jquery-ui.theme.css">
<link type="text/css" rel="stylesheet" href="jqueryui/jquery.timepicker.css">
<body>
<meta charset="utf-8">
<title>index.php</title>
</head>
<body>
<pre>
<?php
if (isset ($_POST['submit'] )) {
/*$query = "INSERT INTO visitors (firstname, lastname, time, date, email, staff) VALUES ('$_POST[firstname]', '$_POST[lastname]', '$_POST[time]', '$_POST[date]', '$_POST[email]', '$_POST[staff]')";
$result = mysqli_query($dbc, $query);
}*/
$statement = $db->prepare("INSERT INTO visitors (firstname, lastname, time, date, email, staff) VALUES (:firstname, :lastname, :time, :date, :email, :staff)");
$statement->execute(array(
"firstname" => $_POST['firstname'],
"lastname" => $_POST['lastname'],
"time" => $_POST['time'],
"date" => $_POST['date'],
"email" => $_POST['email'],
"staff" => $_POST['staff'],
));
}
?>
</pre>
<h1>Navigation</h1>
<form action="index.php" method="post" >
<p>
<label>firstame: </label>
<input type="text" name="firstname" size="50" placeholder="Enter First Name" value="">
</p>
<p>
<label>lastname: </label>
<input type="text" name="lastname" size="50" placeholder="Enter Last Name" value="">
</P>
<p>
<label>date: </label>
<input type="text" id="datepicker" name="date" size="50" placeholder="Enter First Name" value="">
</P>
<p>
<label>email: </label>
<input type="text" name="email" " size="50" placeholder="Enter First Name" value="">
</P>
<p>
<label>time: </label>
<input type="num" id="timer" name="time" size="50" placeholder="Enter First Name" value="">
</p>
<p>
<label>staff: </label>
<input type="text" name="staff" size="50" placeholder="Enter First Name" value="">
</p>
<p>
<button type="submit" name="submit" value="">Add Apointment</button>
</p>
</form>
<script src="jquery-3.2.1.js"></script>
<script src="jqueryui/jquery-ui.js"></script>
<script src="jqueryui/jquery.timepicker.js"></script>
<script>
$(document).ready(function() {
$("#datepicker").datepicker();
});
$(document).ready(function() {
$("#timer").timepicker();
});
</script>
</body>
</html>
【问题讨论】: