dongtan8532 2013-04-24 10:04 采纳率: 0%
浏览 24
已采纳

datepicker没有发布到mysql

I have tried most if not all of the suggestions on this forum, as well as a few others, but I'm still getting 0000-00-00 in MySQL DB even though it echos back correct format.
Here is the PHP code:

    <?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();
            }
        }
   ?>

Here is the datepicker code:

     <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>

Any Help would be appreciated.

  • 写回答

3条回答 默认 最新

  • draxu26480 2013-04-24 10:11
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式