php jquery datepicker mysql 日期格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19223370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery datepicker mysql date format
提问by user2075811
I know there are some answers in this topic but i'm fresh and can't manage to do it
I have insered Jquery UI DatePicker into PHP code but when I'm sending data to MySql I get this Error: Incorrect date value: '' for column 'date' at row 1
我知道这个主题中有一些答案,但我很新鲜,无法做到我已经将 Jquery UI DatePicker 插入到 PHP 代码中,但是当我将数据发送到 MySql 时,我收到此错误: Incorrect date value: '' for column 'date' at row 1
<html>
<head>
<script>
$(document).ready(function() {
$("#datepicker").datepicker({
dateFormat: 'yy-mm-dd'
});
})
</script>
</head>
</body>
<form action="query_insert.php" method="post">
<input type="text" id="datepicker">
<body>
query_insert.php:
query_insert.php:
<?php
$con = mysqli_connect("127.0.0.1", "root", "user", "pass");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO expenses (date) VALUES ('$_POST[datepicker]'
?>
what I have to change to make it work?
我必须改变什么才能使它工作?
回答by C?????N????
You've got multiple things wrong with your html..
你的 html 有很多问题。
</body>
<form action="query_insert.php" method="post">
<input type="text" id="datepicker">
<body>
should be
应该
<body>
<form action="query_insert.php" method="post">
<input type="text" id="datepicker" name="datepicker">
<input type="submit" value="INSERT DATE">
</form>
</body>
Basically, you have to add a name
attribute to the input
field for it to be included in _POST
and _GET
requests, you should also close the form
(but this wont stop it from being posted)
基本上,你有一个添加name
属性的input
字段,它被包含在_POST
和_GET
请求,你也应该关闭form
(但不会被停止发布它)
also, your body
tags were the wrong way around.
此外,你的body
标签是错误的方式。
in your query_insert.php
file you need to finish your INSERT statement:
在您的query_insert.php
文件中,您需要完成 INSERT 语句:
$sql="INSERT INTO expenses (date) VALUES ('$_POST[datepicker]'
should be
应该
$sql="INSERT INTO expenses (date) VALUES ('" . $_POST['datepicker'] . "')";
Warning: I would make sure you validate the $_POST['datepicker']
before inserting it though
警告:我会确保$_POST['datepicker']
在插入之前验证
回答by bysey
dateFormat: 'yy-mm-dd', (OKE)
php function;
php函数;
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
$theValue = ($theValue != "") ?“'”。$theValue 。“'“ : “空值”;
input -> 2013-10-6
输入 -> 2013-10-6
output -> '2013-10-6'
输出 -> '2013-10-6'
Mysql insert => '2013-10-6'
Mysql 插入 => '2013-10-6'
and we are done..
我们完成了..
回答by user2842104
Here you can find more information:
您可以在这里找到更多信息:
But you can try
但是你可以试试
$sql="INSERT INTO expenses (date) VALUES ( date('yyy-mm-dd','$_POST[date]'))