0

我已经尝试了这个论坛上的大部分(如果不是全部)建议,以及其他一些建议,但我仍然在 MySQL DB 中获得0000-00-00,即使它回显了正确的格式。
这是PHP代码:

    <?php
    include_once("includes/form_functions.php");
    // START FORM PROCESSING
    if (isset($_POST['submit'])) { // Form has been submitted.
        $errors = array();
        // perform validations on the form data
        $required_fields = array('location', 'date');
        $errors = array_merge($errors, check_required_fields($required_fields, $_POST));

        $location = trim(mysql_prep($_POST['location']));
        $date = mysql_prep($_POST['date']);
        $adult = mysql_prep($_POST['adult']);
        $child = mysql_prep($_POST['children']);
        $guest = mysql_prep($_POST['guest']);   
        $hg = mysql_prep($_POST['holyghost']);  
        $baptism = mysql_prep($_POST['baptism']);

            if ( empty($errors) ) {
            $query = "INSERT INTO attendance (
            location, date, adult, children, guest, holyghost, baptism
                        ) VALUES (
        '{$location}', {$date}, {$adult}, {$child}, {$guest}, {$hg}, {$baptism} 
                        )"; 
            $result = mysql_query($query, $connection);
            if ($result) {
                $message = "submission completed.";
            } elseif
                ($message = "This form cannot be submitted at this time.");
                 $message .= "<br />" . mysql_error();
            }
        }
   ?>

这是日期选择器代码:

     <head>
     <link rel="stylesheet" href="stylesheets/jquery-ui.css" />
          <script src="javascripts/jquery-ui-1.10.2/jquery-1.9.1.js"></script>
          <script src="javascripts/jquery-ui-1.10.2/ui/jquery-ui.js"></script>
          <script type="text/javascript">
          $(function() {
            $( "#datepicker" ).datepicker({
                dateFormat: "yy-mm-dd"
                });
          });
          </script>
    </head>

任何帮助,将不胜感激。

4

3 回答 3

0

I think you need to use single code(') in your insert statement for date to fix this issue like below..

INSERT INTO attendance (
            location, date, adult, children, guest, holyghost, baptism
                        ) VALUES (
        '{$location}', '{$date}', '{$adult}', '{$child}', '{$guest}', '{$hg}', '{$baptism}' 
                        );

Always use single code(') & mysql_escape_string() function while passing value in MySQL

于 2013-04-24T10:11:49.693 回答
0

我认为是基于 mysql db 列类型。您需要像这样更改 $date 值

`$explode_Date=explode("-",$date);`

$date=date("d-m-Y, mktime(0,0,0,$explode_Date[1],$explode_Date[0],$explode_Date[2]));

然后尝试

于 2013-04-24T10:19:14.833 回答
0
  1. 使用 MySQL 的 STR_TO_DATE() 函数来转换字符串:

插入用户日期值 ('', '$name', STR_TO_DATE('$date', '%m/%d/%Y'))

  1. 将从 jQuery 接收到的字符串转换为 PHP 时间戳——例如使用 strtotime():

    $timestamp = strtotime($_POST['_date']);

然后是:

使用 date() 格式化时间戳:

$date = date('Y-m-d', $timestamp);

使用 FROM_UNIXTIME() 将时间戳直接传递给 MySQL:

插入用户日期值 ('', '$name', FROM_UNIXTIME($timestamp))

于 2013-04-24T10:13:30.777 回答