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

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题