duanke3985 2014-04-29 23:08
浏览 21
已采纳

使用datepicker选择的日期输入不会插入到我的数据库中

Im doing an insert with PDO that it seems correct for me, and the insert is working.

But the date_begin and date_end info is not inserting, my table receivs in this fields the value of :"0000-00-00 00:00:00.000000".

Im using datepicker to choose date.

Do you see what Can be wrong? I dont receive any error or notice!

My insert with pdo:

$insertEvent = $pdo->prepare("INSERT INTO events (title, level, date_begin, date_end) VALUES (:title, :level, :date_begin, :date_end)");  
$insertEvent->bindValue(':title', $f['tile']);
$insertEvent->bindValue(':level', $f['level']);
$insertEvent->bindValue(':date_begin', $f['date_begin']);
$insertEvent->bindValue(':date_end', $f['date_end']);
$insertEvent->execute();          
   echo'Sucess';

If I print this variables, they have the right data that I choose in date picker:

echo $f['date_begin'];
echo $f['date_end'];

My form:

<form action="" method="post" enctype="multipart/form-data">


        <label>
            <span>Title:</span>
            <input type="text"  name="title" value="<?php if(isset($_POST['title'])) echo $f['title']; ?>" />
        </label>

        <label>
            <span class="data">Begin Date:</span>
            <input type="text" class="datepicker" name="date_begin" value="<?php if(isset($_POST['date_begin'])) echo $f['date_begin']; ?>" />
        </label>

        <label>
            <span>End Date:</span>
            <input type="text" class="datepicker" name="date_end" value="<?php if(isset($_POST['date_end'])) echo $f['date_end']; ?>" />
        </label>

         <label>
           <span>Select the level:</span>
            <select name="level">
            <option value="">Select the user level;</option>
            <option value="1">1</option>
            <option value="2">2</option>        
            </select>
        </label>

        <input type="submit" value="Insert" name="sendForm" />

    </form>
  • 写回答

1条回答 默认 最新

  • dongyinpan9284 2014-04-30 01:15
    关注

    Its not working also with datetime, and the datepicker format is like "04/30/2014" and datetime is "0000-00-00". So maybe this is reallty the problem!

    You need to switch it around so that's it's Y-M-D instead of M-D-Y

    Notice the 4x 0000's then the other 2x 00's? Your date is the opposite.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘