这是我的phpcode:
error_reporting(0);
$userLog = $_SESSION['user'];
mysql_select_db("dbwebsite") or die($connect_error);
$time = time();
$event = $_POST['eventname'];
$date = $_POST['datepicker'];
if($event == "" | $date = ""){
echo '<script type="text/javascript">alert("Type your Post First!");</script>';
header("Refresh:-0.0001;user_admin.php");
}
else{
$insert_error = "Your text could not be posted";
$insert = mysql_query("INSERT INTO events VALUES ('','$event','$date','$time')") or die ($insert_error);
header("Location:user_admin.php");
}
?>
这是我的datepicker代码:
<script src="effects/calendar/jquery-1.9.1.js"></script>
<script src="effects/calendar/jquery-ui.js"></script>
<html>
<form action="update_event.php" name="event" id="event" method="post">
<p style="color:#000000">Event name:<input type="text" name="eventname" id="eventname" /></p>
<p style="color:#000000">Event Date:<input type="text" name="datepicker" id="datepicker" /></p>
<br /><input type="submit" name="btnevent" id="btnevent" value="Post event" />
</form>
</html>
0000-00-00显示在我的数据库上,而不是我使用我的datepicker选择的日期。
答案 0 :(得分:0)
您将值$data = ""
指定为null
将if($event == "" | $date = ""){
更改为if($event == "" || $date == ""){
或者你可以试试像isset
这样的东西if(!isset($event) || !isset($date))
答案 1 :(得分:0)
first check the datepicker posted date and change the date format
mysql date format is YYYY-MM-DD
So you change your date format
<?php
$event = $_POST['eventname'];
$date = $_POST['datepicker'];
$dd=date_create($date);
$datepic=date_format($dd,"Y-m-d");
$insert = mysql_query("INSERT INTO events VALUES ('','$event','$datepic','$time')") or die
?>