为什么在表单中日期是必填字段?

19 浏览
0 Comments

为什么在表单中日期是必填字段?

我有一个网页表单,用户需要填写一些信息,其中包括出生日期、描述、教育和城市。如果用户只填写了出生日期(或任何其他字段+出生日期)并保存,那么一切都正常,数据库中的信息会被更新。但如果出生日期字段为空,则信息不会更新,并出现错误:

对象已移动
找到此文档
1292:列'birth_date'中的'--'是不正确的日期值,位于第1行
UPDATE users SET `avatar` = '01\\14',`birth_date` = '--' WHERE user_id = '13'"

系统检查字段是否为空的部分代码如下:

    if ( !empty( $Request->post['birth_date'] ) ) {
        $user_data['birth_date'] = implode('-', $Request->post['birth_date'] );
    }
    if ( !empty( $Request->post['description'] ) ) {
        $user_data['description'] = $Request->post['description'];
    }
    if ( !empty( $Request->post['education_id'] ) ) {
        $user_data['education_id'] = $Request->post['education_id'];
    }
    if ( !empty( $Request->post['city_id'] ) ) {
        $user_data['city_id'] = $Request->post['city_id'];
    }

我的问题是为什么这个检查字段是否为空的代码对于日期字段不起作用?

附注:在MySQL数据库中,birth_date字段的类型是日期,description字段的类型是文本,其他两个字段的类型是整数。

0
0 Comments

为什么表单中的日期是必填字段?

在代码中,有人在评论中回答了这个问题,因为`$Request->post['birth_date']`是一个数组。他们使用了这里的答案来检查是否为空数组:[Check whether an array is empty](https://stackoverflow.com/questions/8328983)。

0